Trains the technique from
LeetCode 3552Grid Teleportation TraversalThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A warehouse floor is given as floor, a list of strings of equal length listed from the top row downwards, so floor[r][c] is the cell in row r and column c. Each character is one of:
"#", a rack that cannot be entered;".", plain open floor;Write m for how many strings floor holds and n for their common length. A picker starts on cell (0, 0), which is never a rack, and the pick face is the last cell of the last row, row m - 1 and column n - 1.
One move goes from the current cell to a cell sharing an edge with it, up, down, left or right, as long as that cell is inside the floor and is not a rack. Each move counts as one.
Chutes give a second way to travel. Standing on a cell that holds a chute, the picker may drop through it and climb out on any other cell holding a chute marked with the same letter, which counts as no moves at all. Over the whole route the picker may drop through at most one chute of each letter: once a letter has been used, the chutes marked with it are sealed for the rest of the route. Chutes never have to be used.
Return the fewest moves the picker needs to get from its starting cell to the pick face, or -1 when there is no way through.
Example 1
Both cells beside the start are racks, but the start holds an A chute and so does the pick face, so dropping through lands the picker on the pick face without a single move.
Example 2
The middle row is solid rack. Dropping through the A chute at the start comes out at the A chute in the bottom row, and two steps to the right along that row reach the pick face.
Example 3
The two cells beside the start are racks and there is no chute anywhere, so the pick face cannot be reached.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def fewest_moves(floor: list[str]) -> int:public int fewestMoves(String[] floor)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.