0Pricing
DSA Interview Prep · Lesson

Burst Balloons: Reverse Interval DP

Solve the burst-balloons problem by thinking in reverse — choosing the last balloon to burst in each interval rather than the first.

The Burst Balloons Problem

Given n balloons with values nums, bursting balloon i earns nums[i-1] * nums[i] * nums[i+1] coins (the product of itself and its current neighbours). After it bursts, the neighbours become adjacent. Find the maximum coins you can collect by bursting all balloons. The naive simulation is hard because bursting changes neighbours — Reverse interval DP elegantly sidesteps this difficulty.

Why Forward Simulation Fails

If we try to define dp[i][j] as maximum coins from bursting balloons in range [i, j] and think about which balloon to burst first, we face a problem: bursting balloon k first means nums[k-1] and nums[k+1] must be the current neighbours — but those balloons might be burst later, changing neighbours dynamically. The state is hard to define cleanly in the forward direction.

All lessons in this course

  1. Interval DP Pattern and Fill Order
  2. Longest Palindromic Subsequence and Substring
  3. Palindrome Partitioning II
  4. Burst Balloons: Reverse Interval DP
← Back to DSA Interview Prep