Unique Paths II

Advanced

Let's imagine a rather adventurous robot that wants to travel from the top-left corner of a grid to the bottom-right corner. It can only move right or down. But wait! There are some obstacles in its way.

Your task is to help this robot find how many unique paths it can take to get to the destination, considering some squares are off-limits due to the obstacles.

Here's how it works: You are given a grid, and its cells can either be a 0 for open spaces, or 1 for obstacles. Your job is to write a function, unique_paths_ii, which takes this grid as its input and returns the number of different paths from the top-left corner to the bottom-right corner.

Example 1

# The grid looks like this: # 0 0 0 # 0 1 0 # 0 0 0 grid = [ [0, 0, 0], [0, 1, 0], [0, 0, 0] ] print(unique_paths_ii(grid)) # Output: 2

Example 2

# The grid looks like this: # 0 1 # 0 0 grid = [ [0, 1], [0, 0] ] print(unique_paths_ii(grid)) # Output: 1

Let's help the robot find its way!

Geek
Inputs

Arg 1:

[[0,0,0],[0,1,0],[0,0,0]]
Expected Output
2
Actual Output