Search⌘ K
AI Features

Unique Paths to Goal

Explore how to calculate the number of unique paths a robot can take from the top-left to the bottom-right corner of a matrix with obstacles. Understand naive recursion and improve it using top-down memoization and bottom-up tabulation dynamic programming approaches to optimize time and space complexity.

Statement

Given a robot located at the top-left corner of an m×nm \times n matrix, determine the number of unique paths the robot can take from start to finish while avoiding all obstacles on the matrix.

The robot can only move either down or right at any time. The robot tries to reach the bottom-right corner of the matrix.

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

Constraints:

  • m ==== matrix.length

  • n ==== matrix[i].length

  • matrix[i][j] is either 1 or 0

  • 11 \leq m, n 7300\leq 7300 ...