1453. Rocks on a Huge Grid
A robot stands on the top-left cell (0, 0) of a rows x cols field and must reach the bottom-right cell (rows - 1, cols - 1). Each step moves it one cell right or one cell down. Every entry rocks[i] = [r, c] is a blocked cell the robot cannot enter; blocked cells are distinct and lie inside the field.
Return the number of different routes from start to target that avoid all blocked cells, modulo 1000000007. If the start or the target is blocked the answer is 0. The field is far too large to fill cell by cell; with R = rocks.length aim for O(R^2 + rows + cols) time using binomial counts between the special cells.
Example 1
- Input:
- rows = 3, cols = 3, rocks = [[1,1]]
- Output:
- 2
- Explanation:
- The centre is blocked, leaving only the two edge routes.
Example 2
- Input:
- rows = 3, cols = 4, rocks = []
- Output:
- 10
- Explanation:
- With no rocks there are C(5,2) = 10 monotone routes.
Example 3
- Input:
- rows = 2, cols = 2, rocks = [[0,1],[1,0]]
- Output:
- 0
- Explanation:
- Both neighbours of the start are blocked, so no route exists.
Constraints
1 ≤ rows, cols ≤ 105
0 ≤ rocks.length ≤ 2000; rocks are distinct cells inside the grid
The result is taken modulo 109 + 7.
How this problem is judged
- Answers
- Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.
Expected complexity
- Time
- O(R^2 + rows + cols)
- Space
- O(R + rows + cols)