1. First row
Every cell in the first row has one path.
const dp = Array(n).fill(1)Typorithm · medium
Step 1 of 8 · intro card
Dynamic Programming
Unique Paths counts grid routes using the fact that each cell is reached from top or left.
The robot only moves right or down.
Each cell adds paths from top and left.
A single row array stores the previous row plus current left value.
State: paths to current column.
Base: first row and column have one path.
Transition: top + left.
Space O(n).
function uniquePaths(m, n) {
const dp = Array(n).fill(1);
for (let row = 1; row < m; row++) {
for (let col = 1; col < n; col++) {
dp[col] += dp[col - 1];
}
}
return dp[n - 1];
}Connect each part of the code to the concept before you type.
Every cell in the first row has one path.
const dp = Array(n).fill(1)Start after the first row base case.
for (let row = 1; row < m; row++)Current paths are from top plus left.
dp[col] += dp[col - 1]Read the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.
Algorithm lab · interactive
InputGrid 3 × 3 · move right or down
Follow temporary values, local state and supporting structures at this step.
↗ The 9-cell working table above is itself auxiliary memory. Input values are shown separately.
Around this step
Small, reproducible examples · ← → step · Space play/pause · Home/End first/last state