Lexicographically Maximal Resulting Array
Learn this problemProblem statement
Amazon's fulfillment centers handle packages of various weights, and they need to optimize their sorting process.
Given an array weight which denotes the weights of n packages, the goal is to create the lexicographically maximal resulting array sorted by non-increasing order of weight using the following operations:
k (a fixed constant) elements from the current array
Note that Operation 2 can also be applied when fewer than k elements remain after the current element; In that case, the entire remaining array is removed.
The resulting array must have packages arranged in non-increasing weight order.
Given an array weight of size n and an integer k, find the lexicographically maximal resulting array sorted by non-increasing order of weight that can be obtained.
Note: An array x is lexicographically greater than an array y if:
x[i] > y[i], where i is the first position where x and y differ, or|x| > |y| and y is a prefix of x (where |x| denotes the size of array x)Function
findMaximumWeights(k: int, weight: int[]) → int[]
Complete the function findMaximumWeights in the editor.
findMaximumWeights has the following parameters:
int k: an integer representing the fixed constantint weight[n]: an array of integers representing the weights of packages
Returns
int[]: the lexicographically maximal resulting array sorted in non-increasing order of weight
Examples
Example 1
k = 1weight = [4, 3, 5, 5, 3]return = [5, 3]
Example 2
k = 2weight = [10, 5, 9, 2, 5]return = [10, 5]Example 3
k = 0weight = [3]return = [3]Constraints
1 <= n <= 1060 <= k < n1 <= weight[i] <= 109
More Amazon problems
- Secure Maximum DeliveriesOA · Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW · Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN · Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN · Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW · Seen Jul 2026
- Maximum System Memory CapacityOA · Seen Jul 2026
- Package Delivery SystemOA · Seen Jul 2026