Skip to content
Decoder

Burst Balloons

Hard

Problem

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.

Example 1

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

Example 2

Input
burst 1: 3*1*5 = 15
Output
[3, 5, 8]

Example 3

Input
burst 5: 3*5*8 = 120
Output
[3, 8]

Example 4

Input
burst 3: 1*3*8 = 24
Output
[8]

Example 5

Input
burst 8: 1*8*1 = 8
Output
total 167

Example 6

Input
nums = [1, 5]
Output
10

Constraints

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

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.