35 · Dynamic Programming

#312 Burst Balloons

Hardsolve on LeetCode ↗

frequently reported atSamsungGoogleAmazon

the problem

In plain words

Balloons have numbers nums[i]. Bursting balloon i earns nums[left] · nums[i] · nums[right], where left/right are its current neighbours (missing neighbours count as 1). Burst all of them; return the maximum total coins.

in nums = [3,1,5,8]

out 167

Burst 1, 5, 3, 8: 3·1·5 + 3·5·8 + 1·3·8 + 1·8·1 = 167.

in nums = [1,5]

out 10

  • 1 ≤ n ≤ 300
  • 0 ≤ nums[i] ≤ 100

your turn

Try it before you peek

Read the examples, say the brute force out loud, then write code: here or on LeetCode ↗. Stuck for 20 minutes? Open one hint at a time.

Solve it in the browser

LeetCode-style: complete the class. Compiled by the real javac (Java 17) and judged right here — nothing is sent anywhere.

    Solutions are hidden so you can try first. Even 20 minutes of real effort makes the answer stick far better than reading it.

    Marking the problem solved, or opening every hint, also shows it.

    practise next

    Similar problems

    1. #5
      Longest Palindromic Substring
      Mediumin Dynamic Programming
    2. #416
      Partition Equal Subset Sum
      Mediumin Dynamic Programming