Skip to main content

Shortest Path in Binary Matrix

Given a square grid of 0s (open) and 1s (blocked), find the length of the shortest path from the top-left to the bottom-right cell, moving through open cells in any of 8 directions (including diagonals).

Read the full walkthrough →
Visualization step 1 of 4. ENQUEUE.
State
Qenqueue
Step 1 / 4
Graph Visualization
8-direction BFS queue: 1
100%
0##0
8-direction BFS queue
(0,0)@1
Traversal
none yet
blue active
amber queued
green visited
gray idle
Step 1 / 4
Step 1 of 4. ENQUEUE. Start BFS from (0,0) with distance 1 -- the first visit to any cell is guaranteed to happen via the shortest path.
Step Explanation1 / 4
ENQUEUE

Start BFS from (0,0) with distance 1 -- the first visit to any cell is guaranteed to happen via the shortest path.

Output0 results
No output yet.