dsa · easy
Shortest Path in Binary Grid
GreyOrangeGraphQueueFoundation
grid of 0 (open) / 1 (wall). 4-direction moves. Return the fewest **moves** from (0,0) to (m-1,n-1), or -1. A 1×1 open cell is 0 moves.
Arguments
grid— the 2D grid
**Example:** [[0,0,0],[1,1,0],[0,0,0]] → 4.
Constraints
1 <= m, n <= 50 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: [[0,0,0],[1,1,0],[0,0,0]] Expected: 4
Example 2
Input: [[0]] Expected: 0