01 Matrix
A medium-tier problem at 51% community acceptance, tagged with Array, Dynamic Programming, Breadth-First Search. Reported in interviews at Graviton and 4 others.
01 Matrix hits your assessment, and your first instinct is dynamic programming. That's where most candidates tank it. You need to find the distance from every cell to the nearest zero in a binary matrix, and the DP approach tanks on larger grids or when you overthink the state transitions. The trick isn't DP at all; it's BFS from all zeros simultaneously. Companies like DoorDash, LinkedIn, and Flipkart ask this regularly. If the multi-source BFS pattern doesn't click during your live OA, StealthCoder surfaces the solution in seconds, invisible to the proctor.
Companies that ask "01 Matrix"
01 Matrix is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share.
Get StealthCoderThe gotcha is that naive DP (iterating the matrix multiple times) works but is slow and fragile. The real pattern is multi-source BFS: queue all zeros at once, then expand outward. Every cell you reach gets labeled with its distance from the nearest zero. This works because BFS guarantees the first time you touch a cell is the shortest path. Most candidates either try DP and waste time, or attempt single-source BFS from each zero separately, which is inefficient. The Array, Breadth-First Search, and Matrix topics converge here. If you blank on the multi-source insight under pressure, StealthCoder hedges the problem instantly during your assessment.
Pattern tags
You know the problem.
Make sure you actually pass it.
01 Matrix recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share. Works on HackerRank, CodeSignal, CoderPad, and Karat.
01 Matrix interview FAQ
Why does DP fail on 01 Matrix?+
DP works for small grids but requires multiple forward and backward passes to converge on the right distances. It's O(n*m*k) where k is iterations. BFS does it in a single pass, O(n*m), and is clearer to code under time pressure.
What is the multi-source BFS trick?+
Initialize the queue with all zero cells at once, not one at a time. Expand layer by layer. Every cell you dequeue and process is guaranteed to be at its minimum distance from any zero. This is the core pattern that makes the problem snap into place.
Is 01 Matrix still asked at top companies?+
Yes. DoorDash, LinkedIn, and Flipkart report it frequently. It's a medium-difficulty favorite because it tests whether you recognize the multi-source BFS pattern versus trying to force DP or greedy approaches.
How does this relate to the other Matrix topics?+
01 Matrix combines Array and Matrix fundamentals with graph traversal logic (BFS). Understanding multi-source shortest path is foundational for harder graph problems. It's a stepping stone, not a dead-end pattern.
What's the acceptance rate telling me?+
Just over 51% means roughly half the candidates get it right on first try. It's a medium-difficulty problem where the 'trick' separates those who drill patterns from those who improvise. If you know BFS, you win.
Want the actual problem statement? View "01 Matrix" on LeetCode →