What you're building
A solveMaze(grid, start, end) function that finds the shortest path from start to end through a 2-D grid, using Breadth-First Search (BFS).
The grid is an array of strings. Each character is either " " (open) or "#" (wall). Coordinates are [row, col].
const grid = [
"S . . #",
"# # . #",
". . . E",
];
Requirements
- Accept
grid(array of strings),start([row,col]),end([row,col]). - Return an array of
[row, col]pairs representing the shortest path from start (inclusive) to end (inclusive). - Return
nullif no path exists. - Move in 4 directions: up, down, left, right β no diagonals.
- Never walk into a
"#"cell; never walk outside the grid bounds. - Each cell in the path must be a distinct coordinate (no revisits).
Stretch goals
- Support diagonal movement with cost
β2. - Return all shortest paths, not just one.
- Animate the frontier expansion (store a snapshot per BFS level).
What this proves
BFS is the canonical shortest-path algorithm on unweighted graphs. Implementing it on a grid is a direct analogy to network routing, map navigation, and social-graph traversal. Interviewers love this problem because it cleanly separates graph thinking from data-structure mechanics.
β‘ 40 XP
solution.jsRuns in your browser
Loading editorβ¦
Tests4 to pass
finds path in open grid
returns null when blocked
single-cell path (start === end)
shortest path length is correct
Run your code to check these.