Steps to the Exit
maze is a list of strings of equal length. '#' is a wall, '.' is open floor, 'S' marks where you stand and 'E' marks the exit. S and E each appear exactly once, and both cells count as open floor.
One move takes you up, down, left or right onto a cell inside the maze that is not a wall. Return the smallest number of moves needed to stand on E, or -1 if the exit cannot be reached.
Example 1
maze ["S.#",".##","..E"]
returns 4
Go down twice, then right twice: 4 moves. The walls block the shorter diagonal corner.
Example 2
maze ["S#E"]
returns -1
A wall stands between the start and the exit, and there is no way around it.
Constraints
1 <= len(maze) <= 101 <= len(maze[i]) <= 10, all rows the same length- Characters are
'#','.','S'and'E', with exactly oneSand oneE
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.