Interval DP

You've seen range-based DP. Here you solve Matrix Chain Multiplication and Burst Balloons, where you split intervals and combine subproblem answers.

38 lessons
142 min
Codeforces: 1800-2200LeetCode: 1900-2200

Lessons

1. What Interval DP Solves

Merge, split, combine

3m

2. When to Use Interval DP

When subproblems nest inside

3m

3. Problem - Zuma

CF 607B - remove palindromes

3m1 problems

4. Zuma - Why Naive Fails

Same endpoints merge free

4m

5. Zuma - Defining the DP

dp[l][r] = moves to clear

4m

6. Zuma - Transition

Match ends, split, or single

4m

7. Zuma - Base Cases

Empty = 0, single = 1

3m

8. Zuma - Implementation

Bottom-up by length

5m1 problems

9. Zuma - Time and Space

O(n³) with O(n²) states

3m

10. Problem - Merge Stones

LC 1000 - merge k at a time

3m1 problems

11. Merge Stones - Feasibility Check

When is one pile possible?

4m

12. Merge Stones - Defining the DP

Piles mod (k-1) matters

4m

13. Merge Stones - Core Logic

Step by k-1 in splits

4m

14. Merge Stones - Implementation

Prefix sums for merge cost

4m1 problems

15. Problem - Coloring Brackets

CF 149D - color matched brackets

3m1 problems

16. Coloring Brackets - Why Naive Fails

Matching structure guides DP

4m

17. Coloring Brackets - Defining the DP

4D state: positions and colors

4m

18. Coloring Brackets - Core Logic

Inside first, then combine

4m

19. Coloring Brackets - Implementation

Stack finds the pairs

4m1 problems

20. Problem - Polygon Triangulation

LC 1039 - triangulate polygon

3m1 problems

21. Polygon Triangulation - Why Naive Fails

One triangle per edge

4m

22. Polygon Triangulation - Defining the DP

dp[l][r] for vertex range

4m

23. Polygon Triangulation - Core Logic

Try each apex vertex k

4m

24. Polygon Triangulation - Implementation

O(n³) for n vertices

4m1 problems

25. Problem - Minimum Cost to Cut Stick

LC 1547 - cutting costs

4m1 problems

26. Minimum Cost to Cut Stick - Solution

Add 0 and n as boundaries

4m1 problems

27. Problem - Strange Printer

LC 664 - overwriting printer

4m1 problems

28. Strange Printer - Solution

Extend matching chars free

4m1 problems

29. Problem - Remove Boxes

LC 546 - group same colors

4m1 problems

30. Remove Boxes - Solution

3D: track trailing boxes

4m1 problems

31. Quiz: Interval DP Patterns

What makes interval DP?

3m1 problems

32. Quiz: Interval DP Edge Cases

Empty ranges, single elements

3m1 problems

33. Common Mistakes in Interval DP

Length order, not index order

4m

34. Problem - Encode String with Shortest Length

LC 471

3m1 problems

35. Encode String with Shortest Length - Implementation

Solution approach

5m1 problems

36. Problem - Palindrome Removal

LC 1246

3m1 problems

37. Palindrome Removal - Implementation

Solution approach

5m1 problems

38. Section Recap

From MCM to Remove Boxes

3m

Practice Problems

1.
Array Shrinkingcodeforces
2.
XOR-pyramidcodeforces
3.

Ready to start learning?

Access all 38 lessons with interactive content and progress tracking.