Every Dynamic Programming Problem Is the Same 5 Patterns
? Every Dynamic Programming Problem Is the Same 5 Patterns ?
Get the free DP Pattern Flowchart — this whole video on one page:
? https://techwithnikola.com/resources/dp-pattern-flowchart (also unlocks my DP Cheatsheet and the rest of the library, and gets you on my biweekly newsletter — system design + engineering deep dives)
Most people learn dynamic programming as a pile of unrelated problems — house robber, knapsack, longest common subsequence — each with its own trick to memorize. But the hard part was never the code. It's deciding what the state is.
And for most of the DP problems an interviewer is likely to hand you, that first answer — where you are — takes one of about five recurring shapes. In this video we work through five problems and find the state in each one, then try the method on a problem the video hasn't covered, to see whether it actually transfers.
? What You'll Learn
? Why "what's the state?" is the only genuinely hard step
? The five shapes a state almost always takes
? The hint in the problem statement that identifies each one
? How a state coordinate doesn't have to be a place you can point at
? What to do when none of the five fit
⏱ Chapters
0:00 — Three puzzles that look nothing alike
1:16 — House Robber: discovering the state
4:19 — Grids: when position needs two numbers
5:41 — Knapsack: the coordinate you can't see
8:54 — Alignment: two independent positions
11:35 — Interval: two ends of the same sequence
12:44 — Burst Balloons: choosing what pops last
16:34 — The flowchart, and a problem we haven't seen
19:10 — All five patterns are the same move
Dynamic programming isn't a bag of tricks. It's one move — define a state, try every decision available there, combine the answers, and solve each state once. Everything else is recognizing which shape you're looking at.
? Free resources DP Pattern Flowchart → https://techwithnikola.com/resources/dp-pattern-flowchart DP Cheatsheet → https://techwithnikola.com/resources/dp-cheatsheet Everything else → https://techwithnikola.com/resources Newsletter → https://techwithnikola.com/newsletter
? The machinery — recurrences, memoization, bottom-up tables: https://www.youtube.com/watch?v=Hdr64lKQ3e4
Problems covered: House Robber · Minimum Path Sum · Partition Equal Subset Sum · Longest Common Subsequence · Longest Palindromic Subsequence · Burst Balloons · Best Time to Buy and Sell Stock with Cooldown