Trains the technique from
LeetCode 1091Shortest Path in Binary MatrixThis 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 stockroom floor is an n x n grid of square tiles given as floor. floor[r][c] is 0 when the tile is free and 1 when a pallet stands on it, blocking the tile.
A picking robot has to get from the tile at the top-left corner to the tile at the bottom-right corner. From its current tile the robot can roll onto any of the up to eight tiles that touch it, including the four that only touch at a corner, as long as that tile is free. A route is the sequence of tiles the robot stands on, starting at the top-left tile and ending at the bottom-right tile, and every tile on it must be free.
Return the number of tiles on the shortest such route, counting both the tile it starts on and the tile it ends on. If no route exists, return -1.
Example 1
The robot rolls corner to corner through the middle tile: (0,0), then (1,1), then (2,2). Three tiles is the fewest possible on any board wider than one tile.
Example 2
Pallets pen the robot into a staircase of free tiles, and the corner steps (0,0), (1,1), (2,2), (3,3) walk straight down it.
Example 3
All three tiles touching the starting corner carry pallets, so the robot cannot leave it and no route exists.
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_tiles_across(floor: list[list[int]]) -> int:public int fewestTilesAcross(int[][] floor)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.