Minimum Product Sum

Minimum Product Sum

FULLTIME

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


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


Example 1 :

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


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^5
  • 1 ≤ arr[i] ≤ 10^5



  • Get one-to-one training from Google Facebook engineers

    Top-notch Professionals

    Learn from Facebook and Google senior engineers interviewed 100+ candidates.
    Most recent interview questions and system design topics gathered from aonecode alumnus.
    One-to-one online classes. Get feedbacks from real interviewers.

    Customized Private Class

    Already a coding expert? - Advance straight to hard interview topics of your interest.
    New to the ground? - Develop basic coding skills with your own designated mentor.
    Days before interview? - Focus on most important problems in target company question bank.