← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
There is an m x n grid with a ball. The ball starts at [startRow, startColumn]. On each move, the ball can move to an adjacent cell in one of four directions: up, down, left, or right. Return the number of paths that move the ball out of the grid boundary in at most maxMove moves. Because the answer can be very large, return it modulo 10^9 + 7.
1 <= m, n <= 10^40 <= startRow < m0 <= startColumn < n0 <= maxMove <= 10^4Example 1:
m = 2, n = 2, startRow = 0, startColumn = 0, maxMove = 23Example 2:
m = 1, n = 2, startRow = 0, startColumn = 0, maxMove = 31dp where dp[i][j][k] represents the number of ways to reach cell (i, j) using k moves.dp array with zeros and set dp[startRow][startColumn][0] = 1 since there is one way to start at the initial position.0 to maxMove - 1, update the dp array by considering the four possible moves from each cell.maxMove moves, sum up all the values in the dp array that are not on the boundary of the grid and return the result modulo 10^9 + 7.This problem tests your understanding of dynamic programming and how to model a problem with a 3D array to keep track of the number of ways to reach each cell using a certain number of moves.