Fundamentals/Festival Game | Bursting Balloons
← PrevNext →
You are given an array targets where each element is the point value of a target in a row. When you hit target i you score targets[i-1] * targets[i] * targets[i+1] points; missing neighbors at the boundaries count as 1. After hitting a target it is removed and the row closes the gap. Return the maximum total score achievable by hitting every target in some order.
Input
targets: an array of positive integers
Output
The maximum total score.
Examples
Example 1
Inputtargets = [3, 1, 5, 8]
Output167
Example 2
Inputtargets = [1, 5]
Output10
Constraints
1 <= targets.length
targets[i] >= 0