Data Structures & Algorithms Master Level Finale
💡
Exercise 162

Burst Balloons 30 XP Hard

LeetCode Ctrl+Enter Run Ctrl+S Save

Burst balloons to maximize coins. When you burst balloon i, you get nums[i-1]*nums[i]*nums[i+1] coins. After bursting, neighbors become adjacent.

Interval DP: think about which balloon to burst last in each interval. dp[l][r] = max coins from bursting all balloons in range (l,r).

💡 Pro tip: Understand this problem deeply — don't just memorize the code. Try explaining the approach out loud as if teaching a friend. If you can explain it simply, you truly understand it!

📋 Instructions
Find maximum coins from bursting [3,1,5,8].
Add 1 to both ends. dp[l][r] = max over k in (l+1..r-1): dp[l][k] + dp[k][r] + nums[l]*nums[k]*nums[r].
🧪 Test Cases
Input
maxCoins([3, 1, 5, 8])
Expected
167
Test case 1
main.py
Hi! I'm Rex 👋
Output
Ready. Press ▶ Run or Ctrl+Enter.