loading

Unique Paths II — Step-by-Step Visualization

mediumLeetCode #63ArrayDynamic ProgrammingMatrix

Robot navigates m×n grid from top-left to bottom-right. Obstacles (1) block paths. Count unique paths.

Algorithm Pattern

2D DP with Obstacles

Key Idea

Like Unique Paths but set dp=0 at obstacles.

Step-by-Step Approach

  1. dp[0][0] = 1 unless obstacle
  2. First row/col blocked if any prior cell is obstacle
  3. dp[i][j] = 0 if obstacle; else sum from top and left

Related Problems