<aside>
This section is part of the 5-hour LeetCode DSA Foundations course by Mukul Raina
Section 17: Dynamic Programming Foundations
Dynamic programming is the technique freshers fear most, but the core concept is simple: recursion with memory. If a recursive solution solves the same subproblem multiple times, store each result the first time and look it up every time after. That single optimization takes exponential algorithms to polynomial.
Section 12 built recursive thinking: base case, recursive case, trust the recursion. Section 13 introduced greedy algorithms and showed where they fail: coin change with denominations [1, 3, 4] and target 6. Greedy picked 4+1+1 = 3 coins. The optimal answer is 3+3 = 2 coins. Section 13 ended with the statement: "When greedy fails and the problem has overlapping subproblems, reach for DP." This section delivers on that promise.
This is foundations-level DP: what DP is, how to convert recursion into DP, the three-part recipe that applies to every DP problem, and four classic problems that appear repeatedly in fresher interviews. Advanced DP patterns (interval DP, DP on trees, bitmask DP, multi-dimensional state design) are covered in C6.
What We'll Cover:
Where DP Connects to Other Sections:
| Connection | Section | How It Applies |
|---|---|---|
| Recursion is the starting point for every DP solution | Section 12: Recursion | DP = recursion + cache for overlapping subproblems |
| Greedy fails when local choices are not globally optimal | Section 13: Greedy | DP considers all choices, greedy considers one |
| Fibonacci memoization was previewed | Section 12: Slide 113 | Same technique, now formalized and applied to new problems |
| Coin change greedy failure was previewed | Section 13: Slide 122 | DP solves it correctly where greedy gave the wrong answer |
| Subsequence problems from Strings section | Section 4: Slide 39 | "Subsequence" problems need DP, not substring/sliding window |
| LIS uses binary search for the O(n log n) optimization | Section 8: Binary Search | Patience sorting variant covered in C6 |
<aside>
Mukul Raina | youtube.com/@mukulraina | slides.mukulraina.com | LinkedIn
</aside>