Loading...
Loading...
Loading...
A maze is a grid. S is the start, E is the exit, . is open floor and # is a wall. You move one step up, down, left or right onto a non-wall cell. Print the fewest steps from S to E, or -1 if the exit cannot be reached.
Example 1
Input
3 4 S.#. ..#. ...E
Output
5
Example 2
Input
1 3 S#E
Output
-1
Try the problem first. Open one hint at a time.
Treat each cell as a node and use BFS from S.
Walls are never pushed onto the queue.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor