Dynamic Programming
Solve each overlapping subproblem once, store it, and build the answer from stored pieces.
This topic is part of Pro.
Free covers the C and Python courses, the first three DSA topics, the opening system design lessons and the beginner AI lessons, all with the full coach. Pro opens the rest of the library in the FollowtheDamnCode app.
What is in it
- 1States and transitionsThe four questions that turn a problem into a DP — state, transition, base case, answer — and top-down vs bottom-up. Pro
- 2One-dimensional DPdp[i] over a sequence — take-or-skip (House Robber), best over choices (Coin Change), and look back over all j < i (LIS). Pro
- 3Grid DPdp[r][c] from the cell above and the cell to the left — paths, costs, obstacles, and squares. Pro
- 4DP on two stringsdp[i][j] over prefixes of both strings — longest common subsequence and edit distance. Pro
- 5Knapsack DPChoose items under a capacity — 0/1 knapsack, subset sum, target sum, and counting combinations. Pro
- 6State machines and interval DPAdd "which mode am I in" to the state (stock trading with cooldown), or solve every subrange (burst balloons). Pro