Burst Balloons

Asked byGoogleMicrosoftAppleBloombergUberAmazon

Problem

Given n balloons with values, bursting a balloon earns coins equal to the product of its two current neighbors' values (using 1 for a missing out-of-bounds neighbor); once burst, its former neighbors become adjacent. Return the maximum coins obtainable by bursting all the balloons.

Examples

Example 1
Input:nums = [3,1,5,8]
Output:167

Constraints

  • 1 <= nums.length <= 300

Solve it in the editor. Sign in free to run your Python or JavaScript against test cases, get a verdict, and track your attempts.

Solve on FeatCode →

How to approach it: the 2-D Dynamic Programming pattern

The same DP idea as 1-D, but the state depends on two indices — often two positions in a grid, or a position in each of two sequences being compared.

Look for this pattern when

  • You're comparing two sequences (finding a longest common subsequence, edit distance).
  • You're computing paths or optimal values across a 2-D grid.

Read the full 2-D Dynamic Programming guide →

Video walkthroughs

Original problem on LeetCode ↗

More 2-D Dynamic Programming problems