Skip to main content

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).

Back to lesson: Practice: Graph Theory Problem Set