Search⌘ K
AI Features

Unique Paths to Goal

Explore the dynamic programming approach to find the number of unique paths a robot can take from start to finish in a grid with obstacles. Learn to handle obstacles, update paths, and optimize space while understanding the core algorithm and its time complexity.

Statement

Given a robot located at the top-left corner of an m×nm \times n grid (marked start in the illustration below), determine the number of unique paths that the robot could take from start to finish while avoiding all obstacles on the grid.

The robot can only move either down or right at any time. The robot tries to reach the bottom-right corner of the grid (marked finish in the illustration below).

An obstacle is marked as 1, and an unoccupied space is marked as 0 in the grid.

Example

Consider the 3×33 \times 3 ...