#576
Out of Boundary Paths
specialist · 895 · lc medium +31 · verified · 48.4% accepted · 3,986 likes · top 34%
Description
A ball starts at [startRow, startColumn] on an m x n grid. Each move shifts the ball to one of the four adjacent cells; moves that cross the boundary count as escaping. With at most maxMove total moves, count the number of distinct paths that take the ball out of bounds. Return the answer modulo 109 + 7.
Example 1:
Input: m = 2, n = 2, maxMove = 2, startRow = 0, startColumn = 0
Output: 6
Example 2:
Input: m = 1, n = 3, maxMove = 3, startRow = 0, startColumn = 1
Output: 12
Code
1
2
3