Maze exit
Filed under Amazon
Free read 1 of 3Confirm allowed directions (4-directional vs 8-directional) and obstacle representation.
The question
Find the minimum number of moves to exit an M*N maze containing obstacles (bombs), starting from (0,0) and moving to (M-1, N-1).
Constraints
- 1 <= M, N <= 100
- Cells contain passable paths, walls, or bombs.
Examples
- Input
- maze = [[0,0],[0,0]], start=(0,0), end=(1,1)
- Output
- 2
- Why
- Takes 2 steps from top-left to bottom-right.
Approach
Confirm allowed directions (4-directional vs 8-directional) and obstacle representation.
Use DFS to explore all paths, which is inefficient and does not guarantee the shortest path without full traversal.
Use Breadth-First Search (BFS) with a queue to find the shortest path in an unweighted graph, tracking visited cells.
Start and end are the same cell; target is completely blocked.
Tips
- What they are testing: Test cases with no possible path, blocked start/end, and multiple alternative paths.
- Common mistake: Using DFS instead of BFS to find the shortest path in an unweighted grid.
Related Amazon questions
Collected from public candidate posts and coding forums. Updated Nov 2026.