Problem
You are given a grid where:
- 1 is the start (exactly one),
- 2 is the end (exactly one),
- 0 is an empty square you can walk on,
- -1 is a wall.
Moving up, down, left or right, count the walks from start to end that visit every non-wall square exactly once.
Example 1
[[1, 0, 0, 0],
Example 2
[0, 0, 0, 0],
Example 3
- Input
- [0, 0, 2, -1]]
- Output
- 2
Example 4
[[1, 0, 0, 0],
Example 5
[0, 0, 0, 0],
Example 6
- Input
- [0, 0, 0, 2]]
- Output
- 4
Example 7
[[0, 1],
Example 8
- Input
- [2, 0]]
- Output
- 0
Constraints
1 <= rows * cols <= 20-1 <= grid[r][c] <= 2There is exactly one start and one end.