type
Matrix LeetCode problems — visual solutions
Every LeetCode problem tagged Matrix — the full catalogue, plus animated visual solutions in Python and Go when a deep-dive exists.
285 problems · 240 animated · 45 locked
Start with a walkthrough
Full Matrix index
- 36Valid SudokuWatch
- 37Sudoku SolverWatch
- 48Rotate ImageWatch
- 54Spiral MatrixWatch
- 59Spiral Matrix IIWatch
- 63Unique Paths IIWatch
- 64Minimum Path SumWatch
- 73Set Matrix ZeroesWatch
- 74Search a 2D MatrixWatch
- 79Word SearchWatch
- 85Maximal RectangleWatch
- 130Surrounded RegionsWatch
- 174Dungeon GameWatch
- 200Number of IslandsWatch
- 212Word Search IIWatch
- 221Maximal SquareWatch
- 240Search a 2D Matrix IIWatch
- 286Walls and GatesLocked
- 289Game of LifeWatch
- 296Best Meeting PointLocked
- 302Smallest Rectangle Enclosing Black PixelsLocked
- 304Range Sum Query 2D - ImmutableWatch
- 308Range Sum Query 2D - MutableLocked
- 311Sparse Matrix MultiplicationLocked
- 317Shortest Distance from All BuildingsLocked
- 329Longest Increasing Path in a MatrixWatch
- 348Design Tic-Tac-ToeLocked
- 361Bomb EnemyLocked
- 363Max Sum of Rectangle No Larger Than KWatch
- 378Kth Smallest Element in a Sorted MatrixWatch
- 407Trapping Rain Water IIWatch
- 417Pacific Atlantic Water FlowWatch
- 419Battleships in a BoardWatch
- 422Valid Word SquareLocked
- 427Construct Quad TreeWatch
- 463Island PerimeterWatch
- 490The MazeLocked
- 498Diagonal TraverseWatch
- 499The Maze IIILocked
- 505The Maze IILocked
- 529MinesweeperWatch
- 531Lonely Pixel ILocked
- 533Lonely Pixel IILocked
- 54201 MatrixWatch
- 562Longest Line of Consecutive One in MatrixLocked
- 566Reshape the MatrixWatch
- 568Maximum Vacation DaysLocked
- 631Design Excel Sum FormulaLocked
- 661Image SmootherWatch
- 675Cut Off Trees for Golf EventWatch
- 694Number of Distinct IslandsLocked
- 695Max Area of IslandWatch
- 711Number of Distinct Islands IILocked
- 723Candy CrushLocked
- 733Flood FillWatch
- 741Cherry PickupWatch
- 749Contain VirusWatch
- 750Number Of Corner RectanglesLocked
- 766Toeplitz MatrixWatch
- 773Sliding PuzzleWatch
- 778Swim in Rising WaterWatch
- 782Transform to ChessboardWatch
- 794Valid Tic-Tac-Toe StateWatch
- 803Bricks Falling When HitWatch
- 807Max Increase to Keep City SkylineWatch
- 827Making A Large IslandWatch
- 832Flipping an ImageWatch
- 835Image OverlapWatch
- 840Magic Squares In GridWatch
- 861Score After Flipping MatrixWatch
- 864Shortest Path to Get All KeysWatch
- 867Transpose MatrixWatch
- 883Projection Area of 3D ShapesWatch
- 885Spiral Matrix IIIWatch
- 892Surface Area of 3D ShapesWatch
- 909Snakes and LaddersWatch
- 931Minimum Falling Path SumWatch
- 934Shortest BridgeWatch
- 959Regions Cut By SlashesWatch
- 980Unique Paths IIIWatch
- 994Rotting OrangesWatch
- 999Available Captures for RookWatch
- 1020Number of EnclavesWatch
- 1030Matrix Cells in Distance OrderWatch
- 1034Coloring A BorderWatch
- 1072Flip Columns For Maximum Number of Equal RowsWatch
- 1074Number of Submatrices That Sum to TargetWatch
- 1091Shortest Path in Binary MatrixWatch
- 1102Path With Maximum Minimum ValueLocked
- 1139Largest 1-Bordered SquareWatch
- 1162As Far from Land as PossibleWatch
- 1198Find Smallest Common Element in All RowsLocked
- 1210Minimum Moves to Reach Target with RotationsWatch
- 1219Path with Maximum GoldWatch
- 1222Queens That Can Attack the KingWatch
- 1253Reconstruct a 2-Row Binary MatrixWatch
- 1254Number of Closed IslandsWatch
- 1260Shift 2D GridWatch
- 1263Minimum Moves to Move a Box to Their Target LocationWatch
- 1267Count Servers that CommunicateWatch
- 1275Find Winner on a Tic Tac Toe GameWatch
- 1277Count Square Submatrices with All OnesWatch
- 1284Minimum Number of Flips to Convert Binary Matrix to Zero MatrixWatch
- 1289Minimum Falling Path Sum IIWatch
- 1292Maximum Side Length of a Square with Sum Less than or Equal to ThresholdWatch
- 1293Shortest Path in a Grid with Obstacles EliminationWatch
- 1301Number of Paths with Max ScoreWatch
- 1314Matrix Block SumWatch
- 1329Sort the Matrix DiagonallyWatch
- 1337The K Weakest Rows in a MatrixWatch
- 1349Maximum Students Taking ExamWatch
- 1351Count Negative Numbers in a Sorted MatrixWatch
- 1368Minimum Cost to Make at Least One Valid Path in a GridWatch
- 1380Lucky Numbers in a MatrixWatch
- 1391Check if There is a Valid Path in a GridWatch
- 1428Leftmost Column with at Least a OneLocked
- 1439Find the Kth Smallest Sum of a Matrix With Sorted RowsWatch
- 1444Number of Ways of Cutting a PizzaWatch
- 1463Cherry Pickup IIWatch
- 1476Subrectangle QueriesWatch
- 1504Count Submatrices With All OnesWatch
- 1536Minimum Swaps to Arrange a Binary GridWatch
- 1559Detect Cycles in 2D GridWatch
- 1568Minimum Number of Days to Disconnect IslandWatch
- 1572Matrix Diagonal SumWatch
- 1582Special Positions in a Binary MatrixWatch
- 1591Strange Printer IIWatch
- 1594Maximum Non Negative Product in a MatrixWatch
- 1595Minimum Cost to Connect Two Groups of PointsWatch
- 1605Find Valid Matrix Given Row and Column SumsWatch
- 1631Path With Minimum EffortWatch
- 1632Rank Transform of a MatrixWatch
- 1672Richest Customer WealthWatch
- 1706Where Will the Ball FallWatch
- 1727Largest Submatrix With RearrangementsWatch
- 1728Cat and Mouse IIWatch
- 1730Shortest Path to Get FoodLocked
- 1738Find Kth Largest XOR Coordinate ValueWatch
- 1765Map of Highest PeakWatch
- 1778Shortest Path in a Hidden GridLocked
- 1810Minimum Path Cost in a Hidden GridLocked
- 1820Maximum Number of Accepted InvitationsLocked
- 1861Rotating the BoxWatch
- 1878Get Biggest Three Rhombus Sums in a GridWatch
- 1886Determine Whether Matrix Can Be Obtained By RotationWatch
- 1895Largest Magic SquareWatch
- 1901Find a Peak Element IIWatch
- 1905Count Sub IslandsWatch
- 1914Cyclically Rotating a GridWatch
- 1926Nearest Exit from Entrance in MazeWatch
- 1937Maximum Number of Points with CostWatch
- 1958Check if Move is LegalWatch
- 1970Last Day Where You Can Still CrossWatch
- 1975Maximum Matrix SumWatch
- 1981Minimize the Difference Between Target and Chosen ElementsWatch
- 1992Find All Groups of FarmlandWatch
- 2017Grid GameWatch
- 2018Check if Word Can Be Placed In CrosswordWatch
- 2022Convert 1D Array Into 2D ArrayWatch
- 2033Minimum Operations to Make a Uni-Value GridWatch
- 2061Number of Spaces Cleaning Robot CleanedLocked
- 2088Count Fertile Pyramids in a LandWatch
- 2123Minimum Operations to Remove Adjacent Ones in MatrixLocked
- 2125Number of Laser Beams in a BankWatch
- 2128Remove All Ones With Row and Column FlipsLocked
- 2132Stamping the GridWatch
- 2133Check if Every Row and Column Contains All NumbersWatch
- 2146K Highest Ranked Items Within a Price RangeWatch
- 2174Remove All Ones With Row and Column Flips IILocked
- 2245Maximum Trailing Zeros in a Cornered PathWatch
- 2257Count Unguarded Cells in the GridWatch
- 2258Escape the Spreading FireWatch
- 2267 Check if There Is a Valid Parentheses String PathWatch
- 2282Number of People That Can Be Seen in a GridLocked
- 2290Minimum Obstacle Removal to Reach CornerWatch
- 2304Minimum Path Cost in a GridWatch
- 2319Check if Matrix Is X-MatrixWatch
- 2326Spiral Matrix IVWatch
- 2328Number of Increasing Paths in a GridWatch
- 2352Equal Row and Column PairsWatch
- 2371Minimize Maximum Value in a GridLocked
- 2373Largest Local Values in a MatrixWatch
- 2387Median of a Row Wise Sorted MatrixLocked
- 2392Build a Matrix With ConditionsWatch
- 2397Maximum Rows Covered by ColumnsWatch
- 2428Maximum Sum of an HourglassWatch
- 2435Paths in Matrix Whose Sum Is Divisible by KWatch
- 2482Difference Between Ones and Zeros in Row and ColumnWatch
- 2500Delete Greatest Value in Each RowWatch
- 2503Maximum Number of Points From Grid QueriesWatch
- 2510Check if There is a Path With Equal Number of 0's And 1'sLocked
- 2536Increment Submatrices by OneWatch
- 2545Sort the Students by Their Kth ScoreWatch
- 2556Disconnect Path in a Binary Matrix by at Most One FlipWatch
- 2573Find the String with LCPWatch
- 2577Minimum Time to Visit a Cell In a GridWatch
- 2596Check Knight Tour ConfigurationWatch
- 2614Prime In DiagonalWatch
- 2617Minimum Number of Visited Cells in a GridWatch
- 2639Find the Width of Columns of a GridWatch
- 2643Row With Maximum OnesWatch
- 2658Maximum Number of Fish in a GridWatch
- 2661First Completely Painted Row or ColumnWatch
- 2664The Knight’s TourLocked
- 2679Sum in a MatrixWatch
- 2684Maximum Number of Moves in a GridWatch
- 2711Difference of Number of Distinct Values on DiagonalsWatch
- 2713Maximum Strictly Increasing Cells in a MatrixWatch
- 2732Find a Good Subset of the MatrixWatch
- 2812Find the Safest Path in a GridWatch
- 2814Minimum Time Takes to Reach Destination Without DrowningLocked
- 2850Minimum Moves to Spread Stones Over GridWatch
- 2852Sum of Remoteness of All CellsLocked
- 2906Construct Product MatrixWatch
- 2923Find Champion IWatch
- 2931Maximum Spending After Buying ItemsWatch
- 2946Matrix Similarity After Cyclic ShiftsWatch
- 2965Find Missing and Repeated ValuesWatch
- 3030Find the Grid of Region AverageWatch
- 3033Modify the MatrixWatch
- 3044Most Frequent PrimeWatch
- 3070Count Submatrices with Top-Left Element and Sum Less Than kWatch
- 3071Minimum Operations to Write the Letter Y on a GridWatch
- 3078Match Alphanumerical Pattern in Matrix ILocked
- 3122Minimum Number of Operations to Satisfy ConditionsWatch
- 3127Make a Square with the Same ColorWatch
- 3142Check if Grid Satisfies ConditionsWatch
- 3148Maximum Difference Score in a GridWatch
- 3195Find the Minimum Area to Cover All Ones IWatch
- 3197Find the Minimum Area to Cover All Ones IIWatch
- 3212Count Submatrices With Equal Frequency of X and YWatch
- 3225Maximum Score From Grid OperationsWatch
- 3239Minimum Number of Flips to Make Binary Grid Palindromic IWatch
- 3240Minimum Number of Flips to Make Binary Grid Palindromic IIWatch
- 3242Design Neighbor Sum ServiceWatch
- 3256Maximum Value Sum by Placing Three Rooks IWatch
- 3257Maximum Value Sum by Placing Three Rooks IIWatch
- 3276Select Cells in Grid With Maximum ScoreWatch
- 3286Find a Safe Walk Through a GridWatch
- 3311Construct 2D Grid Matching Graph LayoutWatch
- 3332Maximum Points Tourist Can EarnWatch
- 3341Find Minimum Time to Reach Last Room IWatch
- 3342Find Minimum Time to Reach Last Room IIWatch
- 3359Find Sorted Submatrices With Maximum Element at Most KLocked
- 3363Find the Maximum Number of Fruits CollectedWatch
- 3391Design a 3D Binary Matrix with Efficient Layer TrackingLocked
- 3393Count Paths With the Given XOR ValueWatch
- 3402Minimum Operations to Make Columns Strictly IncreasingWatch
- 3417Zigzag Grid Traversal With SkipWatch
- 3418Maximum Amount of Money Robot Can EarnWatch
- 3446Sort Matrix by DiagonalsWatch
- 3459Length of Longest V-Shaped Diagonal SegmentWatch
- 3462Maximum Sum With at Most K ElementsWatch
- 3484Design SpreadsheetWatch
- 3529Count Cells in Overlapping Horizontal and Vertical SubstringsWatch
- 3537Fill a Special GridWatch
- 3546Equal Sum Grid Partition IWatch
- 3548Equal Sum Grid Partition IIWatch
- 3552Grid Teleportation TraversalWatch
- 3565Sequential Grid Path CoverLocked
- 3567Minimum Absolute Difference in Sliding SubmatrixWatch
- 3568Minimum Moves to Clean the ClassroomWatch
- 3603Minimum Cost Path with Alternating Directions IIWatch
- 3619Count Islands With Total Value Divisible by KWatch
- 3643Flip Square Submatrix VerticallyWatch
- 3651Minimum Cost Path with TeleportationsWatch
- 3665Twisted Mirror Path CountWatch
- 3725Count Ways to Choose Coprime Integers from RowsWatch
- 3742Maximum Path Score in a GridWatch
- 3797Count Routes to Climb a Rectangular GridWatch
- 3858Minimum Bitwise OR From GridWatch
- 3882Minimum XOR Path in a GridWatch
- 3888Minimum Operations to Make All Grid Elements EqualLocked
- 3898Find the Degree of Each VertexWatch
- 3905Multi Source Flood FillWatch
- 3933Largest Local Values in a Matrix IIWatch
- 3938Maximum Path Intersection Sum in a GridWatch
- 3961Maximize Sum of Device RatingsWatch
- 3988Create Grid With Exactly K Paths IWatch
- 3989Maximum Consistent Columns in a GridWatch
- 3990Create Grid With Exactly K Paths IILocked
- 4003Minimum Cost Path with Alternating Directions IIIWatch
- 4016Maximum Area of Two Non-Overlapping Square SubmatricesWatch
- 4046Minimum Cost Path With At Most K TurnsWatch
- 4052Cyclically Shift Rows and ColumnsWatch