Burst Balloons
Burst all balloons in some order. Bursting a balloon earns its value times its current left and right neighbors; a missing neighbor has value one. Return the greatest possible total.
Example 1
nums = [3,1,5,8]167Explanation
Burst original 1 for 15, then 5 for 120, then 3 for 24, then 8 for 8, totaling 167.
Example 2
nums = [2,4]12Explanation
Burst 2 for 8 then 4 for 4, totaling 12 rather than the reverse order's 10.
Example 3
nums = []0Explanation
No balloons earn no coins.
Constraints
- 0 <= len(nums) <= 300
- Values are 0..100
Function contract
maxCoinsArguments: jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 34 cases, on your device.
[3,1,5,8]