#312

Burst Balloons

Hard Interval DP (last to burst)

  1. Read
  2. Understand
  3. Hints
  4. Approach
  5. Solution
  6. Solved

?The problem

Bursting balloon i earns nums[left] × nums[i] × nums[right], where left and right are its current neighbours (outside counts as 1). Return the maximum coins for bursting all balloons.

This is a short summary in our own words. Read the full statement and examples on LeetCode: open problem ↗

◎Understanding

Really asking: burst all balloons for the most coins.

Why this works: choose the LAST balloon to burst in a range; at that moment its neighbours are the range walls, so the left and right sides are independent.

Example: [3, 1, 5, 8] → padded [1,3,1,5,8,1]

best order gives 167

✦Hints open one at a time

↗Approach

</>Solution (Java)

!Common mistake

Thinking about which balloon goes first — that state is not independent.

Solve on LeetCode ↗
Complexity
  • Time: O(n³).
  • Space: O(n²).
Topic: Dynamic Programming
🎬 Episodes 86–96: video coming soon