FastPrepFastPrep
Problem Brief

Minimum Product Sum

NEW GRADOA
See Tiktok online assessment and hiring insights

Given an array of n integers, arr[n], rearrange them so that the following equation is minimized.

Image of this equation is temporarily shown in the following 👇 I will find a way to do this

Note: The equation uses 1-based indexing.

Function Description

Complete the function findMinimumSum in the editor below.

findMinimumSum has the following parameters:

  1. int arr[n]: the array to optimize

Returns

long: the minimum sum of products from the array

1Example 1

Input
arr = [1, 10, 2, 7, 10, 6, 6]
Output
127
Explanation
Example 1 illustration

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

Limits and guarantees your solution can rely on.

  • 1 ≤ n ≤ 2 * 10^5
  • 1 ≤ arr[i] ≤ 10^5
public long findMinimumSum(int[] arr) {
  // write your code here
}
Input

arr

[1, 10, 2, 7, 10, 6, 6]

Output

127

Sign in to submit your solution.