Unique paths grid all cells
On an m x n grid, cells are marked: 1 is the start (exactly one), 2 is the destination (exactly one), 0 is an empty cell you must walk over, and -1 is an obstacle to avoid. Starting at 1 and moving up/down/left/right, return the number of distinct 4-directional paths from start to destination that visit every non-obstacle cell exactly once. The grid is at most 5x5 (so it has at most 20 walkable cells). Return an integer.
Implement
unique_paths_iii(grid: list[list[int]]) → intExamples
in
[[[1,0,0,0],[0,0,0,0],[0,0,2,-1]]]out2What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 35 min
solution.py
InputExpectedGot
[[[1,0,0,0],[0,0,0,0],[0,0,2,-1]]]2not run yetsample