You are given an `m x n` grid where `1` is the start, `2` is the end, `0` is an empty square and `-1` is an obstacle. Return the number of 4-directional walks from the start to the end that step on every non-obstacle square exactly once.
You are given an m x n grid where 1 is the start, 2 is the end, 0 is an empty square and -1 is an obstacle. Return the number of 4-directional walks from the start to the end that step on every non-obstacle square exactly once.
Example 1:
Input: {"grid":[[1,0,0,0],[0,0,0,0],[0,0,2,-1]]}
Output: 2
Constraints:
m==grid.length
n==grid[i].length
1≤m,n≤20
1≤m⋅n≤20
−1≤grid[i][j]≤2
There is exactly one starting cell and one ending cell.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"grid":[[1,0,0,0],[0,0,0,0],[0,0,2,-1]]}
Count the squares the walk must cover: 9 empty squares plus the start gives 10. A walk counts only if it reaches the 2 with none left.