Description

A robot moves from top-left to bottom-right on a grid. Some cells have obstacles (1). Count unique paths avoiding obstacles. The robot can only move right or down.

Examples

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

Two paths around obstacle.

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

Only one path exists: start at (0,0), move right to (0,1), then move down to (1,1). The obstacle at (1,0) blocks the alternative path of moving down first then right.

Input:obstacleGrid = [[0,1,0,0],[0,0,0,1],[1,0,0,0],[0,0,1,0]]
Output:4
Explanation:

Multiple obstacles create a maze-like grid. Starting from top-left (0,0) to bottom-right (3,3), there are 4 unique paths that navigate around the obstacles at positions (0,1), (1,3), (2,0), and (3,2).

Constraints

  • 1 ≤ m, n ≤ 100

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!