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.
Complete the function findMinimumSum in the editor below.
findMinimumSum has the following parameters:
int arr[n]: the array to optimize
Returns
long: the minimum sum of products from the array
Examples
01 · 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
More Tiktok problems
- Count Cyclic Digit PairsOA · Seen Jun 2026
- Count Skipped Numbers After SubtractionsOA · Seen Jun 2026
- Event ID Check Completion TimesOA · Seen Jun 2026
- Check Even-Position MonotonicityOA · Seen Jun 2026
- Count Alternating Tile GroupsOA · Seen Jun 2026
- Count Even-Digit NumbersOA · Seen Jun 2026
- Inventory Discount TrackerOA · Seen Jun 2026
- Construct WDL StringOA · Seen Jun 2026
public long findMinimumSum(int[] arr) {
// write your code here
}
arr[1, 10, 2, 7, 10, 6, 6]
expected127
checking account