Loading problem…
This problem builds on unique-paths-ii. Complete that first, then load your solution to continue.
The grid contains exactly one start 1, exactly one end 2, empty cells 0, and blocked cells -1. Count routes from the start to the end that visit every non-blocked cell exactly once.
At each step move one cell up, down, left, or right, without leaving the grid. Reaching the end before all empty cells have been visited does not count. The start and end can be anywhere. Restore any temporary grid changes before returning.
Example 1:
Example 2:
Example 3: