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 in the editor.
maximizeSum has the following parameter:
int[] data: an array of integers
Returns
int[]: the permutation of indices that maximizes the sum
data = [3, 6, 1, 4, 2] return = [3, 5, 1, 4, 2]
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.
Larger values stay later. Sort the array based on 1. value 2. if there's a tie, based on index.
:O- Count Promotional PeriodsOA · Seen Jun 2026
- Find Maximum Total Amount (SDE I, Fungible :)Seen Jun 2026
- Get Minimum AmountOA · Seen Jun 2026
- Find Minimum CostOA · Seen Jun 2026
- Get Smallest Base SegmentOA · Seen Jun 2026
- Select Least Resource TasksOA · Seen Jun 2026
- Product Category Group SizesPHONE SCREEN · Seen May 2026
- Count Connected ComponentsPHONE SCREEN · Seen May 2026
public int[] maximizeSum(int[] data) {
// write your code here
}