Paths in grid with obstacles

Write codeMedium20 min

Your task

A robot starts at the top-left of an m x n grid and wants to reach the bottom-right, moving only right or down. Some cells contain obstacles marked 1 (free cells are 0); the robot cannot enter an obstacle. Return the number of distinct obstacle-free paths. If the start or destination cell is an obstacle, return 0. Dimensions are at least 1x1 and at most 100x100.

Examples

unique_paths_with_obstacles(grid: list[list[int]]) -> int
Example 1
Inputunique_paths_with_obstacles([[0, 0, 0], [0, 1, 0], [0, 0, 0]])
Output2