Section 5: Dynamic Programming Patterns
Dynamic programming is the most feared topic in coding interviews, but it does not need to be. At its core, DP is backtracking with memory. In Section 4, we saw that backtracking explores a decision tree exhaustively. When that tree has overlapping subproblems (the same state is reached through different paths), backtracking wastes time recomputing the same answers. DP stores the result of each state the first time it is computed and reuses it for all future requests.
This single idea, caching results to avoid redundant computation, is what converts exponential backtracking into polynomial-time solutions. The skill is not memorizing solutions. It is learning to define the state, write the recurrence, and identify the base cases.
What We’ll Cover:
Where This Appears in Interviews:
| Company Type | How This Section Appears |
|---|---|
| FAANG / Big Tech | Coin Change, LCS, House Robber, and LIS are top-30 most-asked problems |
| Mid-size companies | Climbing Stairs and Unique Paths appear in phone screens |
| Startups | DP is less common but appears in optimization and string matching problems |
| Online assessments | DP problems are common timed questions that separate strong candidates |
Core Idea for This Section: DP applies when the problem has overlapping subproblems and optimal substructure. The skill is defining the state, writing the transition, and identifying the base cases.
Two Required Properties: