Skip to content

Burst Balloons

HardDynamic Programming
Decode it first. Clues, constraints, pattern and plan before any code.

A row of balloons has numbers nums[i]. When you burst balloon i, you earn left * nums[i] * right coins, where left and right are its current neighbours (balloons that have not been burst yet). If a neighbour does not exist, treat it as a balloon with number 1. After bursting, the neighbours become adjacent. Burst all the balloons and return the maximum coins you can collect.

nums = [3, 1, 5, 8]  →  167
  burst 1: 3*1*5 = 15    → [3, 5, 8]
  burst 5: 3*5*8 = 120   → [3, 8]
  burst 3: 1*3*8 = 24    → [8]
  burst 8: 1*8*1 = 8     → total 167
nums = [1, 5]        →  10

Constraints

  • 1 <= nums.length <= 300
  • 0 <= nums[i] <= 100