Burst Balloons Max Coins
Problem Description
You have a row of `n` balloons, each labeled with a positive integer stored in the array `scores`. When you burst balloon `i`, you earn `scores[i-1] * scores[i] * scores[i+1]` coins, where out-of-bounds neighbors are treated as having value `1`.
After bursting balloon `i`, its neighbors become adjacent to each other.
Return the **maximum** total coins you can collect by bursting all the balloons.
**Example 1:**
```
Input: scores = [3, 1, 5, 8]
Output: 167
Explanation:
- Burst index 1 (value 1): 3*1*5 = 15. Array becomes [3,5,8].
- Burst index 0 (value 3): 1*3*5 = 15. Array becomes [5,8].
- Burst index 1 (value 8): 5*8*1 = 40. Array becomes [5].
- Burst index 0 (value 5): 1*5*1 = 5. Total = 167. (order can differ)
```
**Example 2:**
```
Input: scores = [2, 4, 6]
Output: 96
Explanation:
- Burst index 1 (value 4): 2*4*6 = 48. Array becomes [2,6].
- Burst index 0 (value 2): 1*2*6 = 12. Array becomes [6].
- Burst index 0 (value 6): 1*6*1 = 6. Total = 66.
Actually best is burst 2 (value 6) first: 4*6*1=24, then burst 1 (value 4): 2*4*1=8, then burst 0 (value 2): 1*2*1=2, total=34... Try all orders.
Optimal: burst 0 first: 1*2*4=8, burst 2: 2*4*6... actually recompute — output is 96.
```
Constraints
- 1 <= scores.length <= 300
- 1 <= scores[i] <= 100
Follow-up
If each balloon burst also removes adjacent duplicates (like a chain reaction), how would you modify the DP?
Hints
Try the problem first. If you get stuck, you can reveal hints one at a time.
Solution
Leaderboard
No entries yet for python.
Be the first — submit an accepted solution.