Given an m x n grid, a starting cell, and a maximum number of moves, return the number of ways a ball can move out of the grid boundary using one step per move in the four cardinal directions. Pattern focus: Grid path counting. This is a counting DP over time and position.
startRow and startCol are valid grid coordinates
number of ways to exit the grid
Example 1:
Input:
m = 2 n = 2 maxMove = 2 startRow = 0 startCol = 0
Output:
6
Explanation:
There are 6 ways to leave the grid within 2 moves.
Example 2:
Input:
m = 1 n = 3 maxMove = 3 startRow = 0 startCol = 1
Output:
12
Explanation:
The ball can exit in 12 ways.
Example 3:
Input:
m = 3 n = 3 maxMove = 1 startRow = 1 startCol = 1
Output:
0
Explanation:
From the center, one move cannot leave the grid.