Problem Description
Given an integer array A of size N. You have to merge all the elements of the array into one with the minimum possible cost.
The rule for merging is as follows:
Return the minimum possible cost of merging all elements.
1 <= N <= 200
1 <= A[i] <= 103
First and only argument is an integer array A of size N.
Return an integer denoting the minimum cost of merging all elements.
Input 1:
A = [1, 3, 7]
Input 2:
A = [1, 2, 3, 4]
Output 1:
15
Output 2:
19
Explanation 1:
All possible ways of merging: a) {1, 3, 7} (cost = 0) -> {4, 7} (cost = 4) -> {11} (cost = 4+11 = 15) b) {1, 3, 7} (cost = 0) -> {1, 10} (cost = 10) -> {11} (cost = 10+11 = 21) Thus, ans = 15
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 question? Checkout Sample Codes for more details.