An office map app draws the floor as a grid of strings. "S" is where you stand, "E" is the exit, "." is open floor, and "#" is a desk or wall. You can step up, down, left, or right onto any cell that isn't "#".
Write shortestWalk(floor) that returns the fewest steps from "S" to "E", or -1 if the exit can't be reached. There is exactly one "S" and one "E".
Input: floor = ["S.#","..#","#.E"] Output: 4
Go down, right, down, right: (0, 0) → (1, 0) → (1, 1) → (2, 1) → (2, 2).
Input: floor = ["S#E"] Output: -1
The wall between them blocks the only way.
1 <= floor.length, floor[i].length <= 100"S", "E", ".", or "#".Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #412 Shortest Walk Across the Office. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.