A robot starts at the top-left cell of an m x n grid and wants to reach the bottom-right cell. It can only move right or down. Some cells hold obstacles: obstacleGrid[i][j] is 1 for an obstacle and 0 for open space, and the robot can never step onto an obstacle. Return the number of distinct paths from the top-left to the bottom-right cell. The answer is guaranteed to be at most 2 * 10^9.
A robot starts at the top-left cell of an m x n grid and wants to reach the bottom-right cell. It can only move right or down. Some cells hold obstacles: obstacleGrid[i][j] is 1 for an obstacle and 0 for open space, and the robot can never step onto an obstacle. Return the number of distinct paths from the top-left to the bottom-right cell. The answer is guaranteed to be at most 2 * 10^9.
Example 1:
Input: {"obstacleGrid":[[0,0,0],[0,1,0],[0,0,0]]}
Output: 2
Constraints:
m==obstacleGrid.length
n==obstacleGrid[i].length
1≤m,n≤100
obstacleGrid[i][j] is 0 or 1.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"obstacleGrid":[[0,0,0],[0,1,0],[0,0,0]]}
One rolling row of 3 counts is enough. Seed dp[0] = 1: there is exactly one way to stand on the start before moving.