Skip to content
LEETFLIX

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

  1. 36Valid SudokuWatch
  2. 37Sudoku SolverWatch
  3. 48Rotate ImageWatch
  4. 54Spiral MatrixWatch
  5. 59Spiral Matrix IIWatch
  6. 63Unique Paths IIWatch
  7. 64Minimum Path SumWatch
  8. 73Set Matrix ZeroesWatch
  9. 74Search a 2D MatrixWatch
  10. 79Word SearchWatch
  11. 85Maximal RectangleWatch
  12. 130Surrounded RegionsWatch
  13. 174Dungeon GameWatch
  14. 200Number of IslandsWatch
  15. 212Word Search IIWatch
  16. 221Maximal SquareWatch
  17. 240Search a 2D Matrix IIWatch
  18. 286Walls and GatesLocked
  19. 289Game of LifeWatch
  20. 296Best Meeting PointLocked
  21. 302Smallest Rectangle Enclosing Black PixelsLocked
  22. 304Range Sum Query 2D - ImmutableWatch
  23. 308Range Sum Query 2D - MutableLocked
  24. 311Sparse Matrix MultiplicationLocked
  25. 317Shortest Distance from All BuildingsLocked
  26. 329Longest Increasing Path in a MatrixWatch
  27. 348Design Tic-Tac-ToeLocked
  28. 361Bomb EnemyLocked
  29. 363Max Sum of Rectangle No Larger Than KWatch
  30. 378Kth Smallest Element in a Sorted MatrixWatch
  31. 407Trapping Rain Water IIWatch
  32. 417Pacific Atlantic Water FlowWatch
  33. 419Battleships in a BoardWatch
  34. 422Valid Word SquareLocked
  35. 427Construct Quad TreeWatch
  36. 463Island PerimeterWatch
  37. 490The MazeLocked
  38. 498Diagonal TraverseWatch
  39. 499The Maze IIILocked
  40. 505The Maze IILocked
  41. 529MinesweeperWatch
  42. 531Lonely Pixel ILocked
  43. 533Lonely Pixel IILocked
  44. 54201 MatrixWatch
  45. 562Longest Line of Consecutive One in MatrixLocked
  46. 566Reshape the MatrixWatch
  47. 568Maximum Vacation DaysLocked
  48. 631Design Excel Sum FormulaLocked
  49. 661Image SmootherWatch
  50. 675Cut Off Trees for Golf EventWatch
  51. 694Number of Distinct IslandsLocked
  52. 695Max Area of IslandWatch
  53. 711Number of Distinct Islands IILocked
  54. 723Candy CrushLocked
  55. 733Flood FillWatch
  56. 741Cherry PickupWatch
  57. 749Contain VirusWatch
  58. 750Number Of Corner RectanglesLocked
  59. 766Toeplitz MatrixWatch
  60. 773Sliding PuzzleWatch
  61. 778Swim in Rising WaterWatch
  62. 782Transform to ChessboardWatch
  63. 794Valid Tic-Tac-Toe StateWatch
  64. 803Bricks Falling When HitWatch
  65. 807Max Increase to Keep City SkylineWatch
  66. 827Making A Large IslandWatch
  67. 832Flipping an ImageWatch
  68. 835Image OverlapWatch
  69. 840Magic Squares In GridWatch
  70. 861Score After Flipping MatrixWatch
  71. 864Shortest Path to Get All KeysWatch
  72. 867Transpose MatrixWatch
  73. 883Projection Area of 3D ShapesWatch
  74. 885Spiral Matrix IIIWatch
  75. 892Surface Area of 3D ShapesWatch
  76. 909Snakes and LaddersWatch
  77. 931Minimum Falling Path SumWatch
  78. 934Shortest BridgeWatch
  79. 959Regions Cut By SlashesWatch
  80. 980Unique Paths IIIWatch
  81. 994Rotting OrangesWatch
  82. 999Available Captures for RookWatch
  83. 1020Number of EnclavesWatch
  84. 1030Matrix Cells in Distance OrderWatch
  85. 1034Coloring A BorderWatch
  86. 1072Flip Columns For Maximum Number of Equal RowsWatch
  87. 1074Number of Submatrices That Sum to TargetWatch
  88. 1091Shortest Path in Binary MatrixWatch
  89. 1102Path With Maximum Minimum ValueLocked
  90. 1139Largest 1-Bordered SquareWatch
  91. 1162As Far from Land as PossibleWatch
  92. 1198Find Smallest Common Element in All RowsLocked
  93. 1210Minimum Moves to Reach Target with RotationsWatch
  94. 1219Path with Maximum GoldWatch
  95. 1222Queens That Can Attack the KingWatch
  96. 1253Reconstruct a 2-Row Binary MatrixWatch
  97. 1254Number of Closed IslandsWatch
  98. 1260Shift 2D GridWatch
  99. 1263Minimum Moves to Move a Box to Their Target LocationWatch
  100. 1267Count Servers that CommunicateWatch
  101. 1275Find Winner on a Tic Tac Toe GameWatch
  102. 1277Count Square Submatrices with All OnesWatch
  103. 1284Minimum Number of Flips to Convert Binary Matrix to Zero MatrixWatch
  104. 1289Minimum Falling Path Sum IIWatch
  105. 1292Maximum Side Length of a Square with Sum Less than or Equal to ThresholdWatch
  106. 1293Shortest Path in a Grid with Obstacles EliminationWatch
  107. 1301Number of Paths with Max ScoreWatch
  108. 1314Matrix Block SumWatch
  109. 1329Sort the Matrix DiagonallyWatch
  110. 1337The K Weakest Rows in a MatrixWatch
  111. 1349Maximum Students Taking ExamWatch
  112. 1351Count Negative Numbers in a Sorted MatrixWatch
  113. 1368Minimum Cost to Make at Least One Valid Path in a GridWatch
  114. 1380Lucky Numbers in a MatrixWatch
  115. 1391Check if There is a Valid Path in a GridWatch
  116. 1428Leftmost Column with at Least a OneLocked
  117. 1439Find the Kth Smallest Sum of a Matrix With Sorted RowsWatch
  118. 1444Number of Ways of Cutting a PizzaWatch
  119. 1463Cherry Pickup IIWatch
  120. 1476Subrectangle QueriesWatch
  121. 1504Count Submatrices With All OnesWatch
  122. 1536Minimum Swaps to Arrange a Binary GridWatch
  123. 1559Detect Cycles in 2D GridWatch
  124. 1568Minimum Number of Days to Disconnect IslandWatch
  125. 1572Matrix Diagonal SumWatch
  126. 1582Special Positions in a Binary MatrixWatch
  127. 1591Strange Printer IIWatch
  128. 1594Maximum Non Negative Product in a MatrixWatch
  129. 1595Minimum Cost to Connect Two Groups of PointsWatch
  130. 1605Find Valid Matrix Given Row and Column SumsWatch
  131. 1631Path With Minimum EffortWatch
  132. 1632Rank Transform of a MatrixWatch
  133. 1672Richest Customer WealthWatch
  134. 1706Where Will the Ball FallWatch
  135. 1727Largest Submatrix With RearrangementsWatch
  136. 1728Cat and Mouse IIWatch
  137. 1730Shortest Path to Get FoodLocked
  138. 1738Find Kth Largest XOR Coordinate ValueWatch
  139. 1765Map of Highest PeakWatch
  140. 1778Shortest Path in a Hidden GridLocked
  141. 1810Minimum Path Cost in a Hidden GridLocked
  142. 1820Maximum Number of Accepted InvitationsLocked
  143. 1861Rotating the BoxWatch
  144. 1878Get Biggest Three Rhombus Sums in a GridWatch
  145. 1886Determine Whether Matrix Can Be Obtained By RotationWatch
  146. 1895Largest Magic SquareWatch
  147. 1901Find a Peak Element IIWatch
  148. 1905Count Sub IslandsWatch
  149. 1914Cyclically Rotating a GridWatch
  150. 1926Nearest Exit from Entrance in MazeWatch
  151. 1937Maximum Number of Points with CostWatch
  152. 1958Check if Move is LegalWatch
  153. 1970Last Day Where You Can Still CrossWatch
  154. 1975Maximum Matrix SumWatch
  155. 1981Minimize the Difference Between Target and Chosen ElementsWatch
  156. 1992Find All Groups of FarmlandWatch
  157. 2017Grid GameWatch
  158. 2018Check if Word Can Be Placed In CrosswordWatch
  159. 2022Convert 1D Array Into 2D ArrayWatch
  160. 2033Minimum Operations to Make a Uni-Value GridWatch
  161. 2061Number of Spaces Cleaning Robot CleanedLocked
  162. 2088Count Fertile Pyramids in a LandWatch
  163. 2123Minimum Operations to Remove Adjacent Ones in MatrixLocked
  164. 2125Number of Laser Beams in a BankWatch
  165. 2128Remove All Ones With Row and Column FlipsLocked
  166. 2132Stamping the GridWatch
  167. 2133Check if Every Row and Column Contains All NumbersWatch
  168. 2146K Highest Ranked Items Within a Price RangeWatch
  169. 2174Remove All Ones With Row and Column Flips IILocked
  170. 2245Maximum Trailing Zeros in a Cornered PathWatch
  171. 2257Count Unguarded Cells in the GridWatch
  172. 2258Escape the Spreading FireWatch
  173. 2267 Check if There Is a Valid Parentheses String PathWatch
  174. 2282Number of People That Can Be Seen in a GridLocked
  175. 2290Minimum Obstacle Removal to Reach CornerWatch
  176. 2304Minimum Path Cost in a GridWatch
  177. 2319Check if Matrix Is X-MatrixWatch
  178. 2326Spiral Matrix IVWatch
  179. 2328Number of Increasing Paths in a GridWatch
  180. 2352Equal Row and Column PairsWatch
  181. 2371Minimize Maximum Value in a GridLocked
  182. 2373Largest Local Values in a MatrixWatch
  183. 2387Median of a Row Wise Sorted MatrixLocked
  184. 2392Build a Matrix With ConditionsWatch
  185. 2397Maximum Rows Covered by ColumnsWatch
  186. 2428Maximum Sum of an HourglassWatch
  187. 2435Paths in Matrix Whose Sum Is Divisible by KWatch
  188. 2482Difference Between Ones and Zeros in Row and ColumnWatch
  189. 2500Delete Greatest Value in Each RowWatch
  190. 2503Maximum Number of Points From Grid QueriesWatch
  191. 2510Check if There is a Path With Equal Number of 0's And 1'sLocked
  192. 2536Increment Submatrices by OneWatch
  193. 2545Sort the Students by Their Kth ScoreWatch
  194. 2556Disconnect Path in a Binary Matrix by at Most One FlipWatch
  195. 2573Find the String with LCPWatch
  196. 2577Minimum Time to Visit a Cell In a GridWatch
  197. 2596Check Knight Tour ConfigurationWatch
  198. 2614Prime In DiagonalWatch
  199. 2617Minimum Number of Visited Cells in a GridWatch
  200. 2639Find the Width of Columns of a GridWatch
  201. 2643Row With Maximum OnesWatch
  202. 2658Maximum Number of Fish in a GridWatch
  203. 2661First Completely Painted Row or ColumnWatch
  204. 2664The Knight’s TourLocked
  205. 2679Sum in a MatrixWatch
  206. 2684Maximum Number of Moves in a GridWatch
  207. 2711Difference of Number of Distinct Values on DiagonalsWatch
  208. 2713Maximum Strictly Increasing Cells in a MatrixWatch
  209. 2732Find a Good Subset of the MatrixWatch
  210. 2812Find the Safest Path in a GridWatch
  211. 2814Minimum Time Takes to Reach Destination Without DrowningLocked
  212. 2850Minimum Moves to Spread Stones Over GridWatch
  213. 2852Sum of Remoteness of All CellsLocked
  214. 2906Construct Product MatrixWatch
  215. 2923Find Champion IWatch
  216. 2931Maximum Spending After Buying ItemsWatch
  217. 2946Matrix Similarity After Cyclic ShiftsWatch
  218. 2965Find Missing and Repeated ValuesWatch
  219. 3030Find the Grid of Region AverageWatch
  220. 3033Modify the MatrixWatch
  221. 3044Most Frequent PrimeWatch
  222. 3070Count Submatrices with Top-Left Element and Sum Less Than kWatch
  223. 3071Minimum Operations to Write the Letter Y on a GridWatch
  224. 3078Match Alphanumerical Pattern in Matrix ILocked
  225. 3122Minimum Number of Operations to Satisfy ConditionsWatch
  226. 3127Make a Square with the Same ColorWatch
  227. 3142Check if Grid Satisfies ConditionsWatch
  228. 3148Maximum Difference Score in a GridWatch
  229. 3195Find the Minimum Area to Cover All Ones IWatch
  230. 3197Find the Minimum Area to Cover All Ones IIWatch
  231. 3212Count Submatrices With Equal Frequency of X and YWatch
  232. 3225Maximum Score From Grid OperationsWatch
  233. 3239Minimum Number of Flips to Make Binary Grid Palindromic IWatch
  234. 3240Minimum Number of Flips to Make Binary Grid Palindromic IIWatch
  235. 3242Design Neighbor Sum ServiceWatch
  236. 3256Maximum Value Sum by Placing Three Rooks IWatch
  237. 3257Maximum Value Sum by Placing Three Rooks IIWatch
  238. 3276Select Cells in Grid With Maximum ScoreWatch
  239. 3286Find a Safe Walk Through a GridWatch
  240. 3311Construct 2D Grid Matching Graph LayoutWatch
  241. 3332Maximum Points Tourist Can EarnWatch
  242. 3341Find Minimum Time to Reach Last Room IWatch
  243. 3342Find Minimum Time to Reach Last Room IIWatch
  244. 3359Find Sorted Submatrices With Maximum Element at Most KLocked
  245. 3363Find the Maximum Number of Fruits CollectedWatch
  246. 3391Design a 3D Binary Matrix with Efficient Layer TrackingLocked
  247. 3393Count Paths With the Given XOR ValueWatch
  248. 3402Minimum Operations to Make Columns Strictly IncreasingWatch
  249. 3417Zigzag Grid Traversal With SkipWatch
  250. 3418Maximum Amount of Money Robot Can EarnWatch
  251. 3446Sort Matrix by DiagonalsWatch
  252. 3459Length of Longest V-Shaped Diagonal SegmentWatch
  253. 3462Maximum Sum With at Most K ElementsWatch
  254. 3484Design SpreadsheetWatch
  255. 3529Count Cells in Overlapping Horizontal and Vertical SubstringsWatch
  256. 3537Fill a Special GridWatch
  257. 3546Equal Sum Grid Partition IWatch
  258. 3548Equal Sum Grid Partition IIWatch
  259. 3552Grid Teleportation TraversalWatch
  260. 3565Sequential Grid Path CoverLocked
  261. 3567Minimum Absolute Difference in Sliding SubmatrixWatch
  262. 3568Minimum Moves to Clean the ClassroomWatch
  263. 3603Minimum Cost Path with Alternating Directions IIWatch
  264. 3619Count Islands With Total Value Divisible by KWatch
  265. 3643Flip Square Submatrix VerticallyWatch
  266. 3651Minimum Cost Path with TeleportationsWatch
  267. 3665Twisted Mirror Path CountWatch
  268. 3725Count Ways to Choose Coprime Integers from RowsWatch
  269. 3742Maximum Path Score in a GridWatch
  270. 3797Count Routes to Climb a Rectangular GridWatch
  271. 3858Minimum Bitwise OR From GridWatch
  272. 3882Minimum XOR Path in a GridWatch
  273. 3888Minimum Operations to Make All Grid Elements EqualLocked
  274. 3898Find the Degree of Each VertexWatch
  275. 3905Multi Source Flood FillWatch
  276. 3933Largest Local Values in a Matrix IIWatch
  277. 3938Maximum Path Intersection Sum in a GridWatch
  278. 3961Maximize Sum of Device RatingsWatch
  279. 3988Create Grid With Exactly K Paths IWatch
  280. 3989Maximum Consistent Columns in a GridWatch
  281. 3990Create Grid With Exactly K Paths IILocked
  282. 4003Minimum Cost Path with Alternating Directions IIIWatch
  283. 4016Maximum Area of Two Non-Overlapping Square SubmatricesWatch
  284. 4046Minimum Cost Path With At Most K TurnsWatch
  285. 4052Cyclically Shift Rows and ColumnsWatch