Question
Unique Paths with Blockers
You are given an m x n integer matrix obstacleGrid representing a grid.
-
The robot is initially located at the top-left corner (0,0).
-
It wants to reach the bottom-right corner (m-1,n-1).
-
The robot can only move either down or right at any point in time.
-
An obstacle is marked as
1and an empty space is marked as0. -
A path that the robot takes must not include any cell with an obstacle.
Return the total number of unique paths that the robot can take to reach the bottom-right corner modulo 10⁹ + 7.
Input
User Task:
Since this will be a functional problem. You don't have to take input. You just have to complete the function mazeObstacles that takes 3 parameters m, n and obstacleGrid. Where m and n are the grid dimensions and obstacleGrid is a 2D array.
Note :
Since the answer may be very large, return it modulo 1e9 + 7.
Custom Input
The first line contains two space-separated integers m and n — representing the number of rows and columns of the grid.
The next m lines each contain n space-separated integers (either 0 or 1), representing the obstacleGrid.
Since this will be a functional problem. You don't have to take input. You just have to complete the function mazeObstacles that takes 3 parameters m, n and obstacleGrid. Where m and n are the grid dimensions and obstacleGrid is a 2D array.
Note :
Since the answer may be very large, return it modulo 1e9 + 7.
Custom Input
The first line contains two space-separated integers m and n — representing the number of rows and columns of the grid.
The next m lines each contain n space-separated integers (either 0 or 1), representing the obstacleGrid.
Output
Return the number of ways to reach the bottom-right corner of the grid starting from the top-left corner taking modulo 1e9 + 7.
Example
Input:
3 3
0 0 0
0 1 0
0 0 0
Output:
2
Explanation:
There is one obstacle in the middle of the 3x3 grid above.
There are two ways to reach the bottom-right corner:
1. Right -> Right -> Down -> Down
2. Down -> Down -> Right -> Right
3 3
0 0 0
0 1 0
0 0 0
Output:
2
Explanation:
There is one obstacle in the middle of the 3x3 grid above.
There are two ways to reach the bottom-right corner:
1. Right -> Right -> Down -> Down
2. Down -> Down -> Right -> Right