Burst Balloons

You are given N ballons each with a number of coins associated with them.
An array of integers A represents the coins associated with the ith ballon.
You are asked to burst all the balloons.
If the you burst balloon ith you will get A[left] * A[i] * A[right] coins.
Here left and right are adjacent indices of i.
After the burst, the left and right then becomes adjacent.

Find the maximum coins you can collect by bursting the balloons wisely.

Note:

  1. You may imagine A[-1] = A[n] = 1. They are not real therefore you can not burst them.

  2. Your submission will run on multiple test cases if you are using global make sure to clear them.



Input Format

The only argument given is the integer array A.

Output Format

Return the maximum coins you can collect by bursting the balloons wisely.

Constraints

1 <= N <= 100
1 <= A[i] <= 100 

For Example

Input 1:
    A = [3, 1, 5, 8]
Output 1:
    167
    Explanation 1:
        Burst ballon at index 1, coins collected = 3*1*5=15 , A becomes = [3, 5, 8]
        Burst ballon at index 1, coins collected = 3*5*8=120 , A becomes = [3, 8]
        Burst ballon at index 0, coins collected = 1*3*8=24 , A becomes = [8]
        Burst ballon at index 0, coins collected = 1*8*1 = 8
        Total coins collected = 15 + 120 + 24 + 8 = 167

Input 2:
    A = [1, 2, 3, 4, 5]
Output 2:
    110
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Burst Balloons on Interview Code Editor
Sign Up
to access hints and editorial solutions for Burst Balloons

Discussion


Loading...
Click here to start solving coding interview questions