Matrix & Grid Traversal
Trees & GraphsCoordinate navigation, spiral unwrapping, and 2D cellular automations
241 problems·35 Easy·147 Medium·59 Hard
Pattern Study Guide & Cheat Sheet▼
Navigate 2D grids as implicit graphs where each cell (r, c) has up to 4 orthogonal neighbors, using direction arrays [(0,1), (0,-1), (1,0), (-1,0)] and boundary checks.
Core Invariant: Grid = Graph where V = R × C and E ≤ 4 × R × C. Use direction vectors `DIRECTIONS = [(0, 1), (0, -1), (1, 0), (-1, 0)]` to replace 4 repetitive if-statements with a single clean loop.
Recognize it (Keywords & Signals)
- Number of islands / island perimeter / max area of island
- Flood fill / paint bucket tool
- Rotting oranges (multi-source BFS)
- Surrounded regions / capture enclosed territory
- Pacific Atlantic water flow
When NOT to use
Grid has arbitrary jump teleports or diagonal movement when only orthogonal is specified.
How to solve (Step-by-step)
- 1.Define dimensions `ROWS, COLS = len(grid), len(grid[0])`.
- 2.Define directions: `DIRECTIONS = [(0, 1), (0, -1), (1, 0), (-1, 0)]`.
- 3.Centralize boundary check: `0 <= r < ROWS and 0 <= c < COLS and grid[r][c] == target`.
- 4.For DFS/BFS: mark visited immediately (e.g. mutate `grid[r][c] = "0"` in-place or add to `visited` set).
- 5.For multi-source BFS: enqueue all starting sources (e.g. all rotten oranges) at time 0 before running queue.
Watch for (Interview Traps)
- Mixing up `ROWS` and `COLS` in boundary checks (`r < COLS` or `c < ROWS`)
- Mutating grid without confirming if mutation is allowed in interview problem statement
- In multi-source BFS: incrementing time counter even when no fresh items were converted
Multi-Source Grid BFS (Rotting Oranges)
from collections import deque
def oranges_rotting(grid: list[list[int]]) -> int:
ROWS, COLS = len(grid), len(grid[0])
queue = deque()
fresh_count = 0
# 1. Multi-source initialization: find all rotten oranges and count fresh
for r in range(ROWS):
for c in range(COLS):
if grid[r][c] == 2:
queue.append((r, c))
elif grid[r][c] == 1:
fresh_count += 1
if fresh_count == 0:
return 0
minutes = 0
DIRECTIONS = [(0, 1), (0, -1), (1, 0), (-1, 0)]
# 2. BFS spreading level by level
while queue and fresh_count > 0:
minutes += 1
for _ in range(len(queue)):
r, c = queue.popleft()
for dr, dc in DIRECTIONS:
nr, nc = r + dr, c + dc
if 0 <= nr < ROWS and 0 <= nc < COLS and grid[nr][nc] == 1:
grid[nr][nc] = 2 # Infect fresh orange
fresh_count -= 1
queue.append((nr, nc))
return minutes if fresh_count == 0 else -1- Cost
- O(R * C) visits each grid cell at most a constant number of times · O(R * C) for queue/recursion stack in worst case (Can mutate grid in-place to achieve O(1) auxiliary heap space.)
Canonical problems
#200 Number of Islands: Iterate cells; whenever "1" found, trigger DFS to sink connected land
#994 Rotting Oranges: Multi-source BFS tracks time for rot to propagate across grid
#130 Surrounded Regions: Start DFS from boundary "O"s to preserve non-enclosed regions
#417 Pacific Atlantic Water Flow: Reverse flow: DFS upwards from Pacific and Atlantic borders
⌘K
Medium·23 companies·Max freq 100%·Acc 54.3%
Wissen TechnologyNeetCode 150NeetCode 150+20
Hard·20 companies·Max freq 93%·Acc 56.8%
DoorDashWeRideDuolingo+17
#934Shortest Bridge
Medium·18 companies·Max freq 100%·Acc 59.6%
Tower Research CapitalMcKinseyTower Research Capital+15
Medium·17 companies·Max freq 100%·Acc 68.5%
Texas InstrumentsSpaceXGoldman Sachs+14
Hard·16 companies·Max freq 100%·Acc 0.5%
AppFolioPinterestIMC+13
Hard·15 companies·Max freq 100%·Acc 45.0%
ZenefitsGleanApplied Intuition+12
Medium·14 companies·Max freq 100%·Acc 61.2%
Urban CompanyServiceNowNeetCode 150+11
Medium·9 companies·Max freq 53%·Acc 48.8%
eBayUberWalmart Labs+6
Medium·7 companies·Max freq 100%·Acc 68.9%
PoshmarkHudson River TradingMeta+4
Medium·7 companies·Max freq 100%·Acc 45.8%
GuidewireAmerican ExpressGeico+4
Medium·7 companies·Max freq 93%·Acc 64.7%
VisaCapital OneZipRecruiter+4
Medium·6 companies·Max freq 100%·Acc 80.2%
DirectiGoogleMicrosoft+3
Easy·6 companies·Max freq 63%·Acc 79.7%
Arista NetworksAmazonMeta+3
Medium·6 companies·Max freq 38%·Acc 80.8%
AmazonGoogleGoldman Sachs+3
Hard·5 companies·Max freq 100%·Acc 56.2%
VisaRobloxAmazon+2
Medium·5 companies·Max freq 100%·Acc 70.8%
EPAM SystemsMetaAmazon+2
Medium·5 companies·Max freq 100%·Acc 47.8%
PhonePeBloombergAmazon+2
Medium·5 companies·Max freq 88%·Acc 63.9%
CitadelAmazonGoogle+2
Easy·5 companies·Max freq 63%·Acc 74.4%
SalesforceMetaAmazon+2
Medium·5 companies·Max freq 63%·Acc 78.2%
SalesforceBloombergAmazon+2
Hard·5 companies·Max freq 55%·Acc 74.6%
SnapSnapAmazon+2
Medium·4 companies·Max freq 100%·Acc 65.4%
IMCFractal AnalyticsGoogle+1
Easy·4 companies·Max freq 100%·Acc 54.3%
InstacartKaratIndeed+1
Hard·4 companies·Max freq 100%·Acc 0.6%
Hudson River TradingHudson River TradingGoogle+1
Medium·4 companies·Max freq 100%·Acc 71.3%
QuoraUberAmazon+1
Medium·4 companies·Max freq 65%·Acc 55.5%
UberGoogleBloomberg+1
Hard·4 companies·Max freq 63%·Acc 56.1%
AtlassianMicrosoftGoogle+1
Hard·4 companies·Max freq 63%·Acc 63.5%
SalesforceAmazonMicrosoft+1
Hard·4 companies·Max freq 30%·Acc 58.7%
AppleGoogleAmazon+1
Easy·4 companies·Max freq 27%·Acc 68.4%
AmazonMicrosoftMeta+1
Medium·4 companies·Max freq 26%·Acc 71.0%
GoogleBloombergAmazon+1
Medium·4 companies·Max freq 25%·Acc 51.6%
GoogleMicrosoftMeta+1
Medium·4 companies·Max freq 13%·Acc 78.5%
AmazonBloombergMicrosoft+1
Hard·3 companies·Max freq 100%·Acc 24.0%
HuaweiWorldQuantDE Shaw
Medium·3 companies·Max freq 100%·Acc 64.5%
RobinhoodSamsungGoogle
Medium·3 companies·Max freq 52%·Acc 67.6%
UberAmazonGoogle
Hard·3 companies·Max freq 25%·Acc 45.7%
GoogleBloombergAmazon
Medium·2 companies·Max freq 88%·Acc 74.9%
BarclaysGoogle
Medium·2 companies·Max freq 88%·Acc 0.5%
Booking.comBooking.com
Medium·2 companies·Max freq 79%·Acc 56.2%
IntuitGoogle
Medium·2 companies·Max freq 63%·Acc 82.6%
Squarepoint CapitalGoogle
Medium·2 companies·Max freq 27%·Acc 69.7%
MicrosoftAmazon
Hard·2 companies·Max freq 25%·Acc 62.5%
MetaAmazon
Medium·2 companies·Max freq 25%·Acc 37.1%
AmazonGoogle
Hard·2 companies·Max freq 13%·Acc 65.0%
BloombergGoogle
Medium·2 companies·Max freq 13%·Acc 78.8%
AmazonGoogle
Medium·1 companies·Max freq 100%·Acc 66.2%
Amdocs
Hard·1 companies·Max freq 75%·Acc 72.9%
Airbnb
Easy·1 companies·Max freq 70%·Acc 72.8%
IBM
Medium·1 companies·Max freq 67%·Acc 42.4%
Turing
Medium·1 companies·Max freq 25%·Acc 84.5%
Amazon
Hard·1 companies·Max freq 25%·Acc 43.6%
Amazon
Medium·1 companies·Max freq 25%·Acc 52.2%
Google
Medium·1 companies·Max freq 25%·Acc 28.0%
Google
Medium·1 companies·Max freq 25%·Acc 27.6%
Google
Medium·1 companies·Max freq 18%·Acc 25.7%
Google
Hard·1 companies·Max freq 13%·Acc 49.9%
Google
# | Problem | Difficulty | Top Companies↓ | Frequency | Acceptance | |
|---|---|---|---|---|---|---|
| #200 | Number of Islands ArrayDepth-First SearchBreadth-First SearchUnion-FindMatrix | Medium | 100% | 64.7% | ||
| #994 | Rotting Oranges ArrayBreadth-First SearchMatrix | Medium | 100% | 59.0% | ||
| #54 | Spiral Matrix ArrayMatrixSimulation | Medium | 100% | 57.2% | ||
| #48 | Rotate Image ArrayMathMatrix | Medium | 100% | 80.4% | ||
| #79 | Word Search ArrayStringBacktrackingDepth-First SearchMatrix | Medium | 100% | 47.7% | ||
| #36 | Valid Sudoku ArrayHash TableMatrix | Medium | 100% | 0.6% | ||
| #221 | Maximal Square ArrayDynamic ProgrammingMatrix | Medium | 100% | 50.6% | ||
| #212 | Word Search II ArrayStringBacktrackingTrieMatrix | Hard | 89% | 38.6% | ||
| #73 | Set Matrix Zeroes ArrayHash TableMatrix | Medium | 88% | 63.3% | ||
| #74 | Search a 2D Matrix ArrayBinary SearchMatrix | Medium | 100% | 54.3% | ||
| #695 | Max Area of Island ArrayDepth-First SearchBreadth-First SearchUnion-FindMatrix | Medium | 100% | 74.1% | ||
| #329 | Longest Increasing Path in a Matrix ArrayDynamic ProgrammingDepth-First SearchBreadth-First SearchGraph TheoryTopological SortMemoizationMatrixDirected Acyclic Graph | Hard | 93% | 56.8% | ||
| #934 | Shortest Bridge ArrayDepth-First SearchBreadth-First SearchMatrix | Medium | 100% | 59.6% | ||
| #37 | Sudoku Solver ArrayHash TableBacktrackingMatrixAlgorithm XDancing Links | Hard | 100% | 65.6% | ||
| #64 | Minimum Path Sum ArrayDynamic ProgrammingMatrix | Medium | 100% | 68.5% | ||
| #289 | Medium | 100% | 72.8% | |||
| #1293 | Shortest Path in a Grid with Obstacles Elimination ArrayBreadth-First SearchMatrix | Hard | 100% | 0.5% | ||
| #240 | Search a 2D Matrix II ArrayBinary SearchDivide and ConquerMatrix | Medium | 88% | 57.6% | ||
| #85 | Maximal Rectangle ArrayDynamic ProgrammingStackMatrixMonotonic Stack | Hard | 64% | 0.6% | ||
| #317 | Shortest Distance from All Buildings ArrayBreadth-First SearchMatrix | Hard | 100% | 45.0% | ||
| #130 | Surrounded Regions ArrayDepth-First SearchBreadth-First SearchUnion-FindMatrix | Medium | 87% | 0.5% | ||
| #1091 | Shortest Path in Binary Matrix ArrayBreadth-First SearchMatrix | Medium | 81% | 51.8% | ||
| #417 | Pacific Atlantic Water Flow ArrayDepth-First SearchBreadth-First SearchMatrix | Medium | 100% | 61.2% | ||
| #542 | 01 Matrix ArrayDynamic ProgrammingBreadth-First SearchMatrix | Medium | 100% | 54.4% | ||
| #490 | The Maze ArrayDepth-First SearchBreadth-First SearchMatrix | Medium | 63% | 60.5% | ||
| #286 | Walls and Gates ArrayBreadth-First SearchMatrix | Medium | 100% | 64.1% | ||
| #348 | Design Tic-Tac-Toe ArrayHash TableDesignMatrixSimulation | Medium | 94% | 58.8% | ||
| #694 | Number of Distinct Islands ArrayHash TableDepth-First SearchBreadth-First SearchUnion-FindSortingMatrixHash Function | Medium | 92% | 62.9% | ||
| #733 | Flood Fill ArrayDepth-First SearchBreadth-First SearchMatrix | Easy | 88% | 68.6% | ||
| #378 | Kth Smallest Element in a Sorted Matrix ArrayBinary SearchSortingHeap (Priority Queue)Matrix | Medium | 100% | 64.8% | ||
| #498 | Diagonal Traverse ArrayMatrixSimulation | Medium | 100% | 67.3% | ||
| #909 | Snakes and Ladders ArrayBreadth-First SearchMatrix | Medium | 63% | 48.2% | ||
| #59 | Spiral Matrix II ArrayMatrixSimulation | Medium | 53% | 0.8% | ||
| #723 | Candy Crush ArrayTwo PointersMatrixSimulation | Medium | 100% | 77.6% | ||
| #296 | Best Meeting Point ArrayMathSortingMatrix | Hard | 100% | 61.5% | ||
| #741 | Cherry Pickup ArrayDynamic ProgrammingMatrix | Hard | 100% | 39.9% | ||
| #778 | Swim in Rising Water ArrayBinary SearchDepth-First SearchBreadth-First SearchUnion-FindMinimaxHeap (Priority Queue)MatrixDijkstra's Algorithm | Hard | 78% | 68.0% | ||
| #63 | Unique Paths II ArrayDynamic ProgrammingMatrix | Medium | 75% | 0.4% | ||
| #1861 | Rotating the Box ArrayTwo PointersMatrix | Medium | 100% | 82.5% | ||
| #174 | Dungeon Game ArrayDynamic ProgrammingMatrix | Hard | 80% | 0.4% | ||
| #304 | Range Sum Query 2D - Immutable ArrayDesignMatrixPrefix Sum | Medium | 71% | 58.6% | ||
| #631 | Design Excel Sum Formula ArrayHash TableStringGraph TheoryDesignTopological SortMatrix | Hard | 100% | 39.6% | ||
| #529 | Minesweeper ArrayDepth-First SearchBreadth-First SearchMatrix | Medium | 78% | 68.8% | ||
| #1631 | Path With Minimum Effort ArrayBinary SearchDepth-First SearchBreadth-First SearchUnion-FindHeap (Priority Queue)MatrixDijkstra's Algorithm | Medium | 67% | 63.6% | ||
| #463 | Island Perimeter ArrayDepth-First SearchBreadth-First SearchMatrix | Easy | 63% | 74.5% | ||
| #311 | Sparse Matrix Multiplication ArrayHash TableMatrixLinear Algebra | Medium | 63% | 69.3% | ||
| #1926 | Nearest Exit from Entrance in Maze ArrayBreadth-First SearchMatrix | Medium | 53% | 48.8% | ||
| #885 | Medium | 100% | 84.6% | |||
| #419 | Battleships in a Board ArrayDepth-First SearchMatrix | Medium | 100% | 77.6% | ||
| #427 | Construct Quad Tree ArrayDivide and ConquerTreeMatrix | Medium | 88% | 78.5% | ||
| #931 | Minimum Falling Path Sum ArrayDynamic ProgrammingMatrix | Medium | 67% | 60.9% | ||
| #2812 | Find the Safest Path in a Grid ArrayBinary SearchBreadth-First SearchUnion-FindHeap (Priority Queue)Matrix | Medium | 62% | 57.2% | ||
| #1162 | As Far from Land as Possible ArrayDynamic ProgrammingBreadth-First SearchMatrix | Medium | 100% | 52.4% | ||
| #2257 | Count Unguarded Cells in the Grid ArrayMatrixSimulation | Medium | 100% | 68.9% | ||
| #1901 | Find a Peak Element II ArrayBinary SearchMatrix | Medium | 100% | 55.3% | ||
| #864 | Shortest Path to Get All Keys ArrayBit ManipulationBreadth-First SearchMatrix | Hard | 100% | 54.8% | ||
| #2850 | Minimum Moves to Spread Stones Over Grid ArrayDynamic ProgrammingBacktrackingBit ManipulationMatrixBitmask | Medium | 100% | 45.8% | ||
| #3071 | Minimum Operations to Write the Letter Y on a Grid ArrayHash TableMatrixCounting | Medium | 93% | 64.7% | ||
| #3484 | Design Spreadsheet ArrayHash TableStringDesignMatrix | Medium | 78% | 73.9% | ||
| #867 | Transpose Matrix ArrayMatrixSimulation | Easy | 77% | 76.7% | ||
| #1275 | Find Winner on a Tic Tac Toe Game ArrayHash TableMatrixSimulation | Easy | 76% | 54.7% | ||
| #773 | Sliding Puzzle ArrayDynamic ProgrammingBacktrackingBreadth-First SearchMemoizationMatrixHeuristic SearchBidirectional SearchA* Search | Hard | 76% | 74.5% | ||
| #1463 | Cherry Pickup II ArrayDynamic ProgrammingMatrix | Hard | 65% | 72.5% | ||
| #980 | Unique Paths III ArrayBacktrackingBit ManipulationMatrixHamiltonian Path | Hard | 52% | 82.9% | ||
| #1727 | Largest Submatrix With Rearrangements ArrayGreedySortingMatrix | Medium | 100% | 80.2% | ||
| #1559 | Detect Cycles in 2D Grid ArrayDepth-First SearchBreadth-First SearchUnion-FindMatrix | Medium | 100% | 63.4% | ||
| #1572 | Matrix Diagonal Sum ArrayMatrix | Easy | 100% | 84.4% | ||
| #1975 | Maximum Matrix Sum ArrayGreedyMatrix | Medium | 77% | 67.5% | ||
| #2352 | Equal Row and Column Pairs ArrayHash TableMatrixSimulation | Medium | 75% | 71.1% | ||
| #1351 | Count Negative Numbers in a Sorted Matrix ArrayBinary SearchMatrix | Easy | 63% | 79.7% | ||
| #661 | Image Smoother ArrayMatrix | Easy | 50% | 69.4% | ||
| #2965 | Find Missing and Repeated Values ArrayHash TableMathMatrix | Easy | 46% | 83.1% | ||
| #832 | Flipping an Image ArrayTwo PointersBit ManipulationMatrixSimulation | Easy | 42% | 83.9% | ||
| #1277 | Count Square Submatrices with All Ones ArrayDynamic ProgrammingMatrix | Medium | 38% | 80.8% | ||
| #1020 | Number of Enclaves ArrayDepth-First SearchBreadth-First SearchUnion-FindMatrix | Medium | 27% | 72.0% | ||
| #1267 | Count Servers that Communicate ArrayDepth-First SearchBreadth-First SearchUnion-FindMatrixCounting | Medium | 25% | 73.5% | ||
| #3459 | Length of Longest V-Shaped Diagonal Segment ArrayDynamic ProgrammingMemoizationMatrix | Hard | 100% | 56.2% | ||
| #566 | Reshape the Matrix ArrayMatrixSimulation | Easy | 100% | 65.2% | ||
| #2033 | Minimum Operations to Make a Uni-Value Grid ArrayMathSortingMatrix | Medium | 100% | 70.8% | ||
| #3446 | Sort Matrix by Diagonals ArraySortingMatrix | Medium | 100% | 84.7% | ||
| #3418 | Maximum Amount of Money Robot Can Earn ArrayDynamic ProgrammingMatrix | Medium | 100% | 47.8% | ||
| #2661 | First Completely Painted Row or Column ArrayHash TableMatrix | Medium | 88% | 63.9% | ||
| #2258 | Escape the Spreading Fire ArrayBinary SearchBreadth-First SearchMatrix | Hard | 68% | 0.4% | ||
| #2946 | Matrix Similarity After Cyclic Shifts ArrayMathMatrixSimulation | Easy | 63% | 74.4% | ||
| #3195 | Find the Minimum Area to Cover All Ones I ArrayMatrix | Medium | 63% | 78.2% | ||
| #1074 | Number of Submatrices That Sum to Target ArrayHash TableMatrixPrefix Sum | Hard | 55% | 74.6% | ||
| #505 | The Maze II ArrayDepth-First SearchBreadth-First SearchGraph TheoryHeap (Priority Queue)MatrixShortest PathDijkstra's AlgorithmHeuristic SearchA* Search | Medium | 54% | 55.2% | ||
| #1219 | Path with Maximum Gold ArrayBacktrackingMatrix | Medium | 41% | 68.5% | ||
| #1672 | Richest Customer Wealth ArrayMatrix | Easy | 38% | 88.8% | ||
| #1254 | Number of Closed Islands ArrayDepth-First SearchBreadth-First SearchUnion-FindMatrix | Medium | 38% | 67.2% | ||
| #840 | Magic Squares In Grid ArrayHash TableMathMatrix | Medium | 38% | 55.2% | ||
| #2022 | Convert 1D Array Into 2D Array ArrayMatrixSimulation | Easy | 26% | 72.3% | ||
| #1337 | The K Weakest Rows in a Matrix ArrayBinary SearchSortingHeap (Priority Queue)Matrix | Easy | 25% | 74.4% | ||
| #1292 | Maximum Side Length of a Square with Sum Less than or Equal to Threshold ArrayBinary SearchMatrixPrefix Sum | Medium | 100% | 65.4% | ||
| #2133 | Check if Every Row and Column Contains All Numbers ArrayHash TableMatrix | Easy | 100% | 54.3% | ||
| #3225 | Maximum Score From Grid Operations ArrayDynamic ProgrammingMatrixPrefix Sum | Hard | 100% | 0.6% | ||
| #1329 | Sort the Matrix Diagonally ArraySortingMatrix | Medium | 100% | 83.2% | ||
| #1878 | Get Biggest Three Rhombus Sums in a Grid ArrayMathSortingHeap (Priority Queue)MatrixPrefix Sum | Medium | 100% | 71.3% | ||
| #1301 | Number of Paths with Max Score ArrayDynamic ProgrammingMatrix | Hard | 100% | 64.3% | ||
| #1034 | Coloring A Border ArrayDepth-First SearchBreadth-First SearchMatrix | Medium | 88% | 0.5% | ||
| #1139 | Largest 1-Bordered Square ArrayDynamic ProgrammingMatrix | Medium | 88% | 52.3% | ||
| #803 | Bricks Falling When Hit ArrayUnion-FindMatrix | Hard | 88% | 37.5% | ||
| #3341 | Find Minimum Time to Reach Last Room I ArrayGraph TheoryHeap (Priority Queue)MatrixShortest Path | Medium | 65% | 55.5% | ||
| #2326 | Spiral Matrix IV ArrayLinked ListMatrixSimulation | Medium | 64% | 82.3% | ||
| #766 | Toeplitz Matrix ArrayMatrix | Easy | 63% | 69.7% | ||
| #2577 | Minimum Time to Visit a Cell In a Grid ArrayBreadth-First SearchGraph TheoryHeap (Priority Queue)MatrixShortest Path | Hard | 63% | 56.1% | ||
| #3197 | Find the Minimum Area to Cover All Ones II ArrayMatrixEnumeration | Hard | 63% | 63.5% | ||
| #3651 | Minimum Cost Path with Teleportations ArrayDynamic ProgrammingMatrix | Hard | 56% | 45.4% | ||
| #1314 | Matrix Block Sum ArrayMatrixPrefix Sum | Medium | 56% | 76.7% | ||
| #2373 | Largest Local Values in a Matrix ArrayMatrix | Easy | 50% | 87.6% | ||
| #1970 | Last Day Where You Can Still Cross ArrayBinary SearchDepth-First SearchBreadth-First SearchUnion-FindMatrix | Hard | 41% | 68.7% | ||
| #2435 | Paths in Matrix Whose Sum Is Divisible by K ArrayDynamic ProgrammingMatrix | Hard | 30% | 58.7% | ||
| #2643 | Row With Maximum Ones ArrayMatrix | Easy | 29% | 74.2% | ||
| #1886 | Easy | 27% | 68.4% | |||
| #1504 | Count Submatrices With All Ones ArrayDynamic ProgrammingStackMatrixMonotonic Stack | Medium | 26% | 71.0% | ||
| #1289 | Minimum Falling Path Sum II ArrayDynamic ProgrammingMatrix | Hard | 25% | 63.0% | ||
| #1594 | Maximum Non Negative Product in a Matrix ArrayDynamic ProgrammingMatrix | Medium | 25% | 51.6% | ||
| #2017 | Grid Game ArrayMatrixPrefix Sum | Medium | 25% | 60.9% | ||
| #2658 | Maximum Number of Fish in a Grid ArrayDepth-First SearchBreadth-First SearchUnion-FindMatrix | Medium | 13% | 70.3% | ||
| #2906 | Construct Product Matrix ArrayMatrixPrefix Sum | Medium | 13% | 51.7% | ||
| #1072 | Flip Columns For Maximum Number of Equal Rows ArrayHash TableMatrix | Medium | 13% | 78.5% | ||
| #3546 | Equal Sum Grid Partition I ArrayMatrixEnumerationPrefix Sum | Medium | 13% | 52.9% | ||
| #2617 | Minimum Number of Visited Cells in a Grid ArrayDynamic ProgrammingStackBreadth-First SearchUnion-FindHeap (Priority Queue)MatrixMonotonic Stack | Hard | 100% | 24.0% | ||
| #1391 | Check if There is a Valid Path in a Grid ArrayDepth-First SearchBreadth-First SearchUnion-FindMatrix | Medium | 100% | 64.5% | ||
| #1895 | Largest Magic Square ArrayMatrixPrefix Sum | Medium | 100% | 75.2% | ||
| #1582 | Special Positions in a Binary Matrix ArrayMatrix | Easy | 100% | 72.7% | ||
| #861 | Score After Flipping Matrix ArrayGreedyBit ManipulationMatrix | Medium | 100% | 80.3% | ||
| #749 | Contain Virus ArrayDepth-First SearchBreadth-First SearchMatrixSimulation | Hard | 100% | 55.1% | ||
| #1476 | Subrectangle Queries ArrayDesignMatrix | Medium | 100% | 86.4% | ||
| #1349 | Maximum Students Taking Exam ArrayDynamic ProgrammingBit ManipulationMatrixBitmaskMaximum FlowMaximum MatchingBipartite GraphEdmonds–Karp AlgorithmMPM AlgorithmPush-Relabel AlgorithmMinimum CutMatching (Graph)Flow NetworkDinic's Algorithm | Hard | 92% | 54.0% | ||
| #2545 | Sort the Students by Their Kth Score ArraySortingMatrix | Medium | 88% | 86.0% | ||
| #1380 | Lucky Numbers in a Matrix ArrayMatrix | Easy | 88% | 80.1% | ||
| #807 | Max Increase to Keep City Skyline ArrayGreedyMatrix | Medium | 81% | 86.5% | ||
| #1428 | Leftmost Column with at Least a One ArrayBinary SearchMatrixInteractive | Medium | 75% | 55.3% | ||
| #1102 | Path With Maximum Minimum Value ArrayBinary SearchDepth-First SearchBreadth-First SearchUnion-FindHeap (Priority Queue)MatrixDijkstra's Algorithm | Medium | 68% | 54.7% | ||
| #568 | Maximum Vacation Days ArrayDynamic ProgrammingMatrix | Hard | 63% | 46.8% | ||
| #3552 | Grid Teleportation Traversal ArrayHash TableBreadth-First SearchMatrix | Medium | 63% | 23.9% | ||
| #1632 | Rank Transform of a Matrix ArrayUnion-FindGraph TheoryTopological SortSortingMatrix | Hard | 56% | 42.4% | ||
| #3417 | Zigzag Grid Traversal With Skip ArrayMatrixSimulation | Easy | 55% | 65.5% | ||
| #3342 | Find Minimum Time to Reach Last Room II ArrayGraph TheoryHeap (Priority Queue)MatrixShortest Path | Medium | 52% | 67.6% | ||
| #2536 | Increment Submatrices by One ArrayMatrixPrefix Sum | Medium | 42% | 73.8% | ||
| #1778 | Shortest Path in a Hidden Grid ArrayDepth-First SearchBreadth-First SearchMatrixInteractive | Medium | 40% | 44.7% | ||
| #2596 | Check Knight Tour Configuration ArrayDepth-First SearchBreadth-First SearchMatrixSimulation | Medium | 25% | 61.7% | ||
| #1260 | Shift 2D Grid ArrayMatrixSimulation | Easy | 25% | 68.1% | ||
| #1765 | Map of Highest Peak ArrayBreadth-First SearchMatrix | Medium | 25% | 76.0% | ||
| #308 | Range Sum Query 2D - Mutable ArrayDesignBinary Indexed TreeSegment TreeMatrixSqrt Decomposition | Medium | 25% | 45.5% | ||
| #363 | Max Sum of Rectangle No Larger Than K ArrayBinary SearchMatrixPrefix SumOrdered Set | Hard | 25% | 45.7% | ||
| #3286 | Find a Safe Walk Through a Grid ArrayBreadth-First SearchGraph TheoryHeap (Priority Queue)MatrixShortest Path | Medium | 15% | 55.3% | ||
| #1914 | Cyclically Rotating a Grid ArrayMatrixSimulation | Medium | 13% | 74.1% | ||
| #3030 | Find the Grid of Region Average ArrayMatrix | Medium | 100% | 43.8% | ||
| #1992 | Find All Groups of Farmland ArrayDepth-First SearchBreadth-First SearchMatrix | Medium | 100% | 75.5% | ||
| #2931 | Maximum Spending After Buying Items ArrayGreedySortingHeap (Priority Queue)Matrix | Hard | 100% | 61.4% | ||
| #3070 | Count Submatrices with Top-Left Element and Sum Less Than k ArrayMatrixPrefix Sum | Medium | 88% | 74.9% | ||
| #2639 | Find the Width of Columns of a Grid ArrayMatrix | Easy | 88% | 70.5% | ||
| #2146 | K Highest Ranked Items Within a Price Range ArrayBreadth-First SearchSortingHeap (Priority Queue)Matrix | Medium | 88% | 0.5% | ||
| #2328 | Number of Increasing Paths in a Grid ArrayDynamic ProgrammingDepth-First SearchBreadth-First SearchGraph TheoryTopological SortMemoizationMatrix | Hard | 88% | 57.3% | ||
| #2061 | Number of Spaces Cleaning Robot Cleaned ArrayMatrixSimulation | Medium | 80% | 64.6% | ||
| #3619 | Count Islands With Total Value Divisible by K ArrayDepth-First SearchBreadth-First SearchUnion-FindMatrix | Medium | 79% | 56.2% | ||
| #3078 | Match Alphanumerical Pattern in Matrix I ArrayHash TableStringMatrix | Medium | 75% | 65.3% | ||
| #1605 | Find Valid Matrix Given Row and Column Sums ArrayGreedyMatrixFlow Network | Medium | 63% | 82.6% | ||
| #675 | Cut Off Trees for Golf Event ArrayBreadth-First SearchHeap (Priority Queue)Matrix | Hard | 63% | 36.6% | ||
| #782 | Transform to Chessboard ArrayMathBit ManipulationMatrix | Hard | 50% | 51.6% | ||
| #2684 | Maximum Number of Moves in a Grid ArrayDynamic ProgrammingMatrix | Medium | 41% | 58.8% | ||
| #1730 | Shortest Path to Get Food ArrayBreadth-First SearchMatrix | Medium | 38% | 57.3% | ||
| #1820 | Maximum Number of Accepted Invitations ArrayDepth-First SearchGraph TheoryMatrixMaximum FlowMaximum MatchingBipartite GraphEdmonds–Karp AlgorithmMPM AlgorithmPush-Relabel AlgorithmMatching (Graph)Flow NetworkDinic's Algorithm | Medium | 38% | 52.7% | ||
| #3462 | Maximum Sum With at Most K Elements ArrayGreedySortingHeap (Priority Queue)Matrix | Medium | 29% | 60.9% | ||
| #3212 | Count Submatrices With Equal Frequency of X and Y ArrayMatrixPrefix Sum | Medium | 27% | 69.7% | ||
| #1810 | Minimum Path Cost in a Hidden Grid ArrayDepth-First SearchBreadth-First SearchGraph TheoryHeap (Priority Queue)MatrixInteractiveShortest Path | Medium | 27% | 59.0% | ||
| #711 | Number of Distinct Islands II ArrayHash TableDepth-First SearchBreadth-First SearchUnion-FindSortingMatrixHash Function | Hard | 25% | 55.5% | ||
| #1439 | Find the Kth Smallest Sum of a Matrix With Sorted Rows ArrayBinary SearchHeap (Priority Queue)Matrix | Hard | 25% | 62.5% | ||
| #2125 | Number of Laser Beams in a Bank ArrayMathStringMatrix | Medium | 25% | 87.0% | ||
| #1981 | Minimize the Difference Between Target and Chosen Elements ArrayDynamic ProgrammingMatrix | Medium | 25% | 37.1% | ||
| #2290 | Minimum Obstacle Removal to Reach Corner ArrayBreadth-First SearchGraph TheoryHeap (Priority Queue)MatrixShortest Path0-1 BFSDijkstra's Algorithm | Hard | 25% | 70.9% | ||
| #361 | Bomb Enemy ArrayDynamic ProgrammingMatrix | Medium | 25% | 52.8% | ||
| #1536 | Minimum Swaps to Arrange a Binary Grid ArrayGreedyMatrix | Medium | 18% | 70.1% | ||
| #3665 | Twisted Mirror Path Count ArrayDynamic ProgrammingMatrix | Medium | 16% | 47.5% | ||
| #3742 | Maximum Path Score in a Grid ArrayDynamic ProgrammingMatrix | Medium | 15% | 53.7% | ||
| #3363 | Find the Maximum Number of Fruits Collected ArrayDynamic ProgrammingMatrix | Hard | 13% | 65.0% | ||
| #3643 | Flip Square Submatrix Vertically ArrayTwo PointersMatrix | Easy | 13% | 79.4% | ||
| #2319 | Check if Matrix Is X-Matrix ArrayMatrix | Easy | 13% | 66.9% | ||
| #2500 | Delete Greatest Value in Each Row ArraySortingHeap (Priority Queue)MatrixSimulation | Easy | 13% | 80.0% | ||
| #3567 | Minimum Absolute Difference in Sliding Submatrix ArraySortingMatrix | Medium | 13% | 78.8% | ||
| #3548 | Equal Sum Grid Partition II ArrayHash TableMatrixEnumerationPrefix Sum | Hard | 13% | 39.4% | ||
| #2428 | Maximum Sum of an Hourglass ArrayMatrixPrefix Sum | Medium | 100% | 76.4% | ||
| #1210 | Minimum Moves to Reach Target with Rotations ArrayBreadth-First SearchMatrix | Hard | 100% | 52.4% | ||
| #1253 | Reconstruct a 2-Row Binary Matrix ArrayGreedyMatrix | Medium | 100% | 49.1% | ||
| #3391 | Design a 3D Binary Matrix with Efficient Layer Tracking ArrayHash TableDesignHeap (Priority Queue)MatrixOrdered Set | Medium | 100% | 66.2% | ||
| #3033 | Modify the Matrix ArrayMatrix | Easy | 100% | 69.3% | ||
| #1030 | Matrix Cells in Distance Order ArrayMathGeometrySortingMatrix | Easy | 100% | 74.4% | ||
| #3148 | Maximum Difference Score in a Grid ArrayDynamic ProgrammingMatrix | Medium | 88% | 48.3% | ||
| #3332 | Maximum Points Tourist Can Earn ArrayDynamic ProgrammingMatrix | Medium | 75% | 47.9% | ||
| #2387 | Median of a Row Wise Sorted Matrix ArrayBinary SearchMatrix | Medium | 75% | 71.3% | ||
| #1284 | Minimum Number of Flips to Convert Binary Matrix to Zero Matrix ArrayHash TableBit ManipulationBreadth-First SearchMatrix | Hard | 75% | 72.9% | ||
| #3402 | Minimum Operations to Make Columns Strictly Increasing ArrayGreedyMatrix | Easy | 70% | 72.8% | ||
| #3122 | Minimum Number of Operations to Satisfy Conditions ArrayDynamic ProgrammingMatrix | Medium | 67% | 42.4% | ||
| #2132 | Stamping the Grid ArrayGreedyMatrixPrefix Sum | Hard | 63% | 35.6% | ||
| #2397 | Maximum Rows Covered by Columns ArrayBacktrackingBit ManipulationMatrixEnumeration | Medium | 50% | 58.2% | ||
| #2282 | Number of People That Can Be Seen in a Grid ArrayStackMatrixMonotonic Stack | Medium | 50% | 47.4% | ||
| #2664 | The Knight’s Tour ArrayBacktrackingMatrix | Medium | 38% | 72.7% | ||
| #3393 | Count Paths With the Given XOR Value ArrayDynamic ProgrammingBit ManipulationMatrix | Medium | 31% | 40.8% | ||
| #2018 | Check if Word Can Be Placed In Crossword ArrayMatrixEnumeration | Medium | 26% | 50.9% | ||
| #750 | Number Of Corner Rectangles ArrayMathDynamic ProgrammingMatrix | Medium | 25% | 67.9% | ||
| #1958 | Check if Move is Legal ArrayMatrixEnumeration | Medium | 25% | 50.2% | ||
| #2482 | Difference Between Ones and Zeros in Row and Column ArrayMatrixSimulation | Medium | 25% | 84.5% | ||
| #2123 | Minimum Operations to Remove Adjacent Ones in Matrix ArrayDepth-First SearchGraph TheoryMatrixEdmonds–Karp AlgorithmMPM AlgorithmPush-Relabel AlgorithmFlow NetworkDinic's Algorithm | Hard | 25% | 43.6% | ||
| #3537 | Fill a Special Grid ArrayDivide and ConquerMatrix | Medium | 25% | 70.8% | ||
| #1444 | Number of Ways of Cutting a Pizza ArrayDynamic ProgrammingMemoizationMatrixPrefix Sum | Hard | 25% | 61.6% | ||
| #2510 | Check if There is a Path With Equal Number of 0's And 1's ArrayDynamic ProgrammingMatrix | Medium | 25% | 52.2% | ||
| #835 | Image Overlap ArrayMatrix | Medium | 25% | 64.1% | ||
| #1728 | Cat and Mouse II ArrayMathDynamic ProgrammingGraph TheoryTopological SortMemoizationMinimaxMatrixGame TheoryZero-Sum Game | Hard | 25% | 40.4% | ||
| #2392 | Build a Matrix With Conditions ArrayGraph TheoryTopological SortMatrixDirected Acyclic Graph | Hard | 25% | 79.3% | ||
| #2556 | Disconnect Path in a Binary Matrix by at Most One Flip ArrayDynamic ProgrammingDepth-First SearchBreadth-First SearchMatrix | Medium | 25% | 28.0% | ||
| #302 | Smallest Rectangle Enclosing Black Pixels ArrayBinary SearchDepth-First SearchBreadth-First SearchMatrix | Hard | 25% | 61.0% | ||
| #2088 | Count Fertile Pyramids in a Land ArrayDynamic ProgrammingMatrix | Hard | 25% | 66.4% | ||
| #3529 | Count Cells in Overlapping Horizontal and Vertical Substrings ArrayStringRolling HashString MatchingMatrixHash Function | Medium | 25% | 27.6% | ||
| #562 | Longest Line of Consecutive One in Matrix ArrayDynamic ProgrammingMatrix | Medium | 25% | 50.6% | ||
| #1706 | Where Will the Ball Fall ArrayMatrixSimulation | Medium | 25% | 72.3% | ||
| #1591 | Strange Printer II ArrayGraph TheoryTopological SortMatrixDirected Acyclic Graph | Hard | 25% | 61.1% | ||
| #1595 | Minimum Cost to Connect Two Groups of Points ArrayDynamic ProgrammingBit ManipulationMatrixBitmaskBipartite GraphSuccessive Shortest Path AlgorithmMatching (Graph)Minimum-Cost FlowFlow Network | Hard | 25% | 50.4% | ||
| #1738 | Find Kth Largest XOR Coordinate Value ArrayDivide and ConquerBit ManipulationSortingHeap (Priority Queue)MatrixPrefix SumQuickselect | Medium | 25% | 64.4% | ||
| #422 | Valid Word Square ArrayMatrix | Easy | 25% | 42.9% | ||
| #531 | Lonely Pixel I ArrayHash TableMatrix | Medium | 25% | 62.7% | ||
| #533 | Lonely Pixel II ArrayHash TableMatrix | Medium | 25% | 48.9% | ||
| #2304 | Minimum Path Cost in a Grid ArrayDynamic ProgrammingMatrix | Medium | 25% | 68.2% | ||
| #2128 | Remove All Ones With Row and Column Flips ArrayMathBit ManipulationMatrix | Medium | 25% | 76.2% | ||
| #2174 | Remove All Ones With Row and Column Flips II ArrayBit ManipulationBreadth-First SearchMatrix | Medium | 25% | 67.4% | ||
| #2267 | Check if There Is a Valid Parentheses String Path ArrayDynamic ProgrammingMatrixBracket Sequences | Hard | 25% | 40.5% | ||
| #2371 | Minimize Maximum Value in a Grid ArrayUnion-FindGraph TheoryTopological SortSortingMatrix | Hard | 25% | 70.1% | ||
| #2923 | Find Champion I ArrayMatrix | Easy | 25% | 73.6% | ||
| #3044 | Most Frequent Prime ArrayHash TableMathMatrixCountingEnumerationNumber TheoryPrimality TestSieve TheoryPrime Number Sieve | Medium | 25% | 46.2% | ||
| #3240 | Minimum Number of Flips to Make Binary Grid Palindromic II ArrayTwo PointersMatrix | Medium | 18% | 25.7% | ||
| #3858 | Minimum Bitwise OR From Grid ArrayGreedyBit ManipulationMatrix | Medium | 18% | 27.4% | ||
| #892 | Surface Area of 3D Shapes ArrayMathGeometryMatrix | Easy | 13% | 71.1% | ||
| #3568 | Minimum Moves to Clean the Classroom ArrayHash TableBit ManipulationBreadth-First SearchMatrix | Medium | 13% | 26.9% | ||
| #3797 | Count Routes to Climb a Rectangular Grid ArrayDynamic ProgrammingMatrixPrefix Sum | Hard | 13% | 25.1% | ||
| #1263 | Minimum Moves to Move a Box to Their Target Location ArrayBreadth-First SearchHeap (Priority Queue)Matrix | Hard | 13% | 49.9% | ||
| #2573 | Find the String with LCP ArrayStringDynamic ProgrammingGreedyUnion-FindMatrix | Hard | 13% | 63.1% | ||
| #883 | Projection Area of 3D Shapes ArrayMathGeometryMatrix | Easy | 13% | 76.4% | ||
| #2614 | Prime In Diagonal ArrayMathMatrixNumber Theory | Easy | 13% | 38.0% | ||
| #499 | The Maze III ArrayStringDepth-First SearchBreadth-First SearchGraph TheoryHeap (Priority Queue)MatrixShortest PathDijkstra's AlgorithmHeuristic SearchA* Search | Hard | 13% | 52.5% | ||
| #3882 | Minimum XOR Path in a Grid ArrayDynamic ProgrammingBit ManipulationMatrix | Medium | 13% | 39.9% |
Showing 241 of 241 problems in Matrix & Grid TraversalFiltered: All Companies