All postsDynamic Programming PatternAugust 9, 202639 min readpatterndynamic programmingCommon Dynamic Programming Patterns to solve any problemIndexDynamic Programming Interview MasteryPart I — DP Foundations1. What Is Dynamic Programming?2. Not Every DP Problem Has Take/SkipBut some DP problems have no choice3. The Most Important DP Concept: State4. Why Use an Explicit Memo Array?5. The Universal DP WorkflowPart II — DP Pattern CatalogPattern 1: 1D / Linear DPStep 1: Define the stateStep 2: Identify choicesStep 3: RecursionStep 4: Explicit MemoizationStep 5: Convert to Bottom-UpStep 6: Space OptimizationStep 1: Define the stateStep 2: Find the dependencyStep 3: RecursionStep 4: Explicit MemoizationStep 5: Bottom-UpProblemsPattern 2: 0/1 KnapsackWhen to UseRecognition SignalsProblems0/1 Knapsack FamilyPattern 3: Unbounded KnapsackWhen to UseRecognition SignalsProblemsPattern 4: Two-Sequence DPWhen to UseRecognition SignalsSub-Pattern 1: Sequence ComparisonExample: LCSRecursionMemoizationBottom-UpLCS ReconstructionBottom-Up ReconstructionSub-Pattern 2: Two-Source ConsumptionRecurrenceSub-Pattern 3: Pattern MatchingRecurrenceComparing the Sub-PatternsCommon MistakeProblem SetPattern 5: Grid DPWhen to UseRecognition SignalsProblemsPattern 6: Longest Increasing SubsequenceWhen to UseRecognition SignalsExampleProblemsPattern 7: State Machine DPWhen to UseRecognition SignalsProblemsPattern 8: Interval DP / Matrix Chain MultiplicationWhen to UseRecognition SignalsRecognition PatternMatrix Chain MultiplicationProblemsPattern 9: Tree DPWhen to UseRecognition SignalsProblemsPattern 10: DAG / Graph DPWhen to UseRecognition SignalsLongest Path in DAGRecursive + MemoizationProblemsPattern 11: Bitmask DPWhen to UseRecognition SignalsProblemsPattern 12: Digit DPWhen to UseRecognition SignalsProblemsPart III — DP Direction and Tabulation1. Choosing DP DirectionIf the state depends on smaller indicesIf the state depends on future indicesIf the state is an intervalThe Real Rule2. The Complete DP Pattern Map3. Maximum, Minimum, Count, or Boolean?MaximumMinimumCountBoolean4. The Universal Recursive DP Template5. The Interview DP Checklist6. DP Pattern Cheat Sheet7. What to Master First for InterviewsTier 1 — EssentialTier 2 — Very ImportantTier 3 — Advanced8. How to Practice Each Pattern9. The Real Goal10. Final TakeawayRelatedGraph Pattern45 min readgraphpatternSliding Window Pattern19 min readsliding-windowpatternDynamic Programming Examples29 min readexamplesdynamic programming