Overview
This is the "Hello World" of 2D Grid DP. You are placed at `(0, 0)` and must reach `(m-1, n-1)` moving only down and right.
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Find the number of possible unique paths from the top-left to the bottom-right of a grid, moving only down or right.
This is the "Hello World" of 2D Grid DP. You are placed at `(0, 0)` and must reach `(m-1, n-1)` moving only down and right.
Let `dp[r][c]` be the number of unique paths to reach the cell at row `r` and column `c`.
Any cell in the first row can only be reached by moving right. Any cell in the first column can only be reached by moving down. Thus, they all have exactly 1 path.
For any inner cell, you could have arrived from the cell directly above it, or the cell directly to its left. Thus, `dp[r][c] = dp[r-1][c] + dp[r][c-1]`.