Dsa
Graphs Bfs
Warm-up
Shortest Path in Grid
You have an m x n grid represented by 0s and 1s, where 0 represents an open cell and 1 represents an obstacle. Given the starting position (sx, sy) and the destination position (dx, dy), return the minimum number of steps required to reach the destination from the start position. If it is impossible, return -1. You can only move in four directions (up, down, left, right).
Example Input:
4 5
0 0 0 0 0
0 1 1 1 0
0 0 0 1 0
0 0 0 0 0
1 1
2 3
Example Output:
4
Key concepts
graphsbfsgrid
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now