Dynamic Programming Basics
Spot repeated subproblems, then reuse each answer with memoization or a table. Learn to name the state, transition, base case and answer.
The problem
You climb a staircase of n steps. Each move goes up 1 or 2 steps. How many different ways reach the top?
Think about the last move. It came from step n - 1 or from step n - 2. So:
That is a recursive answer. It is correct, and it is very slow.
1 of 9