InferenceAI

Enter at least two characters to search.

Start free

Burst Balloons

hardDynamic Programming40 min50 XP

Bursting balloon ii earns nums[left] * nums[i] * nums[right], where left and right are its current neighbours (treat missing neighbours as 1). Return the maximum coins from bursting all balloons.

Requirements

  • Interval DP in O(n3)O(n^3): choose the balloon burst last in each interval.

Examples

EXAMPLE WALKTHROUGHclassic

A guided view of the published example, not a trace of your code.

INPUT[[3,1,5,8]]
TASKburst_balloons_score()
EXPECTED OUTPUT167

Start with the input values shown in this example.

Example 1 of 3

Input: nums = [3,1,5,8]

Output: 167

Explanation: classic

Input: nums = [1,5]

Output: 10

Explanation: two balloons

Input: nums = []

Output: 0

Explanation: none

Hint 1

Pad nums with 1 at both ends.

Hint 2

best[l][r] = max over k in (l, r) of best[l][k] + best[k][r] + v[l] * v[k] * v[r].

Topics

DSADynamic ProgrammingPython