Skip to content

Practice Unique Paths II

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#63
LeetCode Problem

Unique Paths II

Problem Statement

Given an m by n grid, count paths from its top-left cell to its bottom-right cell using only steps right or down. A cell with value 1 is blocked; a cell with value 0 is open. A path cannot enter a blocked cell. Return the count of valid paths. The answer is guaranteed to be at most 2 * 10^9.

Source: Unique Paths II on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
obstacleGrid = [[0,0,0],[0,1,0],[0,0,0]]
Output
2

# Example 2

Input
obstacleGrid = [[0,1],[0,0]]
Output
1

Constraints

m == obstacleGrid.length
n == obstacleGrid[i].length
1 <= m, n <= 100
obstacleGrid[i][j] is 0 or 1.

Related LeetCode Problems

Practice more problems similar to Unique Paths II.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.