Maze Runner
Asked at Meta· Onsite
Reported by the problem's creator, not verified
You are given a maze as a list of equal-length strings, one per row. S marks the start and E the exit, and each appears exactly once. # is a wall that cannot be entered and . is open floor. Each move goes one cell up, down, left or right and costs 1 step.
Implement shortest_path(grid), which returns the fewest steps needed to walk from S to E, or -1 if E cannot be reached.
Examples
Example 1
Input: grid =
["S..#","#.#.","...E"]Output:
5Explanation: The only route goes right once, down twice, then right twice into
E: 5 steps; the walls leave nothing shorter.
Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.