Maximize Sum of Array Multiplication

Maximize Sum of Array Multiplication

FULLTIME
You have an array of data (index starting from 1) data = [3, 6, 1, 4, 2].
Rearrange the data such that after the permutation, 1 * data[1] + 2 * data[2] + 3 * data[3] + ... n * data[n] is the largest.
Return the permutations as an array where each element represents the index after permutation (also starting from 1). .
If there are multiple equivalent answers, return the lexicographically smallest one..

Complete the function maximizeSum
maximizeSum has the following parameter:
int[] data: an array of integers
Returns
int[]: the permutation of indices that maximizes the sum

Example:
Input: data = [3, 6, 1, 4, 2]
Output: [3, 5, 1, 4, 2]
Explanation:
The permutation [3, 5, 1, 4, 2] is chosen because the sum 1 * 1 + 2 * 2 + 3 * 3 + 4 * 4 + 5 * 6 is the largest sum you can get.
Potentional Solution: Larger values stay later. Sort the array based on 1. value 2. if there's a tie, based on index.



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.