Classic example
Input
[3, 1, 5, 8]
Output
167
Burst balloons in order 1, 5, 3, 8 (or other optimal order) to collect total 167 coins.
Full lesson preview
Given balloons with numbers, determine the maximum coins obtainable by choosing the order to burst them.
Problem statement
Task
Examples
Input
[3, 1, 5, 8]
Output
167
Burst balloons in order 1, 5, 3, 8 (or other optimal order) to collect total 167 coins.
Input format
Output format
Constraints
Samples
Input
[1, 5]
Output
10
Burst 1 then 5: coins = 1*1*5 + 1*5*1 = 5 + 5 = 10.