02.03 · Cheat sheet
Recursion & DP
Work out any recursion or DP problem in the same order, every time.
The recipe
- Promise: what does
f(...)return? One sentence. - Base case: the smallest input with an obvious answer.
- Smaller step: trust the smaller call and build your answer from it.
- Check: every call gets closer to the base case.
Base cases and combining
| Question | Good end | Impossible | Combine |
|---|---|---|---|
| Count ways | 1 | 0 | + |
| Possible? | true | false | || |
| Minimum | 0 | (int) 1e9 | Math.min |
| Maximum | 0 | (int) -1e9 | Math.max |
| List all | save a copy | return | call all |
Check guards before reading: i == a.length before a[i].
solulu Pro
Continue this cheat sheet with Pro
Inside: 8 sections.
- The recipe
- Base cases and combining
- Pick or skip
- Backtracking
- Memo in 4 steps
- Memo → table
- +2 more
Lifetime ₹1,999 ₹999 · Launch offer
Item 7 of 12 · updated 2026-10-13