Trains the technique from
LeetCode 980Unique Paths IIIThis 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 the grid floor, where each cell carries one of four markings:
1 marks the single starting bay,2 marks the single finishing bay,0 marks an open bay that has to be swept,-1 marks a blocked bay that cannot be entered.A sweep begins on the starting bay and ends on the finishing bay, moving each time to a bay that shares an edge with the current one. It has to cover every open bay, and no bay may be stood on more than once. The starting and finishing bays are not open bays, and each of them is stood on exactly once, as the two ends of the sweep.
Return how many different sweeps the floor allows. Two sweeps differ when the order of bays they stand on differs.
Example 1
Every bay is open, so all nine have to be stood on with the last one being the far corner. Going down the left column, one step right, up the middle column, one step right, then down the right column is one way. Going along the top row, one step down, back along the middle row, one step down, then along the bottom row is the other. Nothing else covers the floor.
Example 2
All four bays have to be stood on, which takes three steps from the starting bay. Three steps around a square of four bays always end up next door to where they began, never diagonally across, so no sweep works.
Example 3
The blocked bay leaves one route: down, then across.
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 unique_paths_i_i_i(floor: list[list[int]]) -> int:public int uniquePathsIII(int[][] floor)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.