Burst Balloons
Problem
You are given n balloons in a row, each labelled with a number nums[i]. Bursting balloon i earns you nums[i-1] * nums[i] * nums[i+1] coins, after which the balloon disappears and its former neighbours become adjacent. Treat any missing neighbour beyond either end of the row as having value 1. Choose the bursting order that maximises the total coins, and return that total.
- Up to 250 balloons.
- Each balloon's number is between 0 and 120.
Examples
nums = [4, 2, 6, 3]→136. Burst 2 (426=48), then 6 (463=72), then 3 (431=12), then 4 (141=4); 48+72+12+4 = 136.nums = [2, 9]→27. Bursting 9 first earns 191 + 121 = 11; bursting 2 first earns 129 + 191 = 27, so order matters.nums = [6]→6. One balloon with implicit 1s on both sides.
Hints
- Choosing which balloon to burst first makes the remaining balloons' neighbours depend on that choice, so the two sides do not separate. Try the opposite question.
- If balloon
kis the last one burst within the range(lo, hi), its neighbours at that moment are exactlyloandhi, whatever happened earlier. - Interval DP on the padded array:
dp[lo][hi] = max over k of dp[lo][k] + nums[lo]*nums[k]*nums[hi] + dp[k][hi].
Last reviewed 8 September 2026
Approach · Solution (Python) · Complexity · Follow-ups · Company variations · Tests
The rest of this question — the worked approach, the Python solution with passing tests, complexity, follow-ups and how each company frames it — is part of the guides.
Get the full guide
Pick the company you're interviewing with. Each guide has every question tiered for that loop — one-time purchase, lifetime access.
Also in: Apple, Google, Meta, Microsoft, Netflix
Interviewing at more than one? All 6 guides for $499 · save $395
Not ready to buy? Get the free starter pack — 13 questions with full solutions.