Fewest Moves Through a Maze
A maze is given as a list of equal-length strings: S is the start, E the exit, # a wall and . open floor. Each move goes one cell up, down, left or right, never through a wall or off the grid.
Return the fewest moves needed to walk from S to E, or -1 if the exit cannot be reached.
Examples
["S.#",
"..#",
"#.E"] → 4
["S#E"] → -1
["S...",
"###.",
"E..."] → 8In the first example the walk goes down, right, down, right.
Constraints
- Up to 100 rows and 100 columns, with exactly one
Sand oneE. - Aim for O(n) in the number of cells: each cell should be reached once.
Console
›Run to see what your code prints
Run checks the 3 visible cases here, in your browser. Submit runs all 7 on the judge, 4 of them hidden, and measures how your solution scales.
Expected is the reference solution's answer, from the judge. An input that breaks the statement's other rules may get any answer.