Practice · 4 of 5
Maze Escape
CHALLENGE
Difficulty: intermediate+25 XP
**Description:** Shortest walk length from S to E on a grid moving through '.' cells
(up/down/left/right), or -1 if E is unreachable. S and E count as walkable.
**Input:** Line 1: n m (1 <= n, m <= 1000). Next n lines: m characters each
('.' open, '#' wall, exactly one 'S', exactly one 'E').
**Output:** One integer — the minimum number of moves, or -1.
**Example:** 2 3 / S.. / .#E -> 3 (right, right, down).
Press Submit to check your solution.
Back to lesson: Practice: Graph Theory Problem Set