Problem · Array
Minimum Product Sum
Learn this problemProblem statement
Given an array of n integers, arr[n], rearrange them so that the following equation is minimized:
sum(i = 1 to n - 1) of arr[i] * arr[i + 1]
Note: The equation uses 1-based indexing.
Complete the function findMinimumSum in the editor below.
findMinimumSum has the following parameter:
int arr[n]: the array to optimize
Return a long: the minimum sum of products from the array.
Function
findMinimumSum(arr: int[]) → longExamples
Example 1
arr = [1, 10, 2, 7, 10, 6, 6]return = 127
One of the optimal rearrangements is arr = [10, 1, 7, 6, 6, 2, 10], producing the result 10 * 1 + 1 * 7 + 7 * 6 + 6 * 6 + 6 * 2 + 2 * 10 = 127.
Constraints
1 <= n <= 2 * 10^51 <= arr[i] <= 10^5