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)
Complete the function lexicographicallyMaximalResultingArray in the editor.
lexicographicallyMaximalResultingArray has the following parameters:
int weight[n]: an array of integers representing the weights of packagesint k: an integer representing the fixed constant
Returns
int[]: the lexicographically maximal resulting array sorted in non-increasing order of weight
k = 1 weight = [4, 3, 5, 5, 3] return = [5, 3]

k = 2 weight = [10, 5, 9, 2, 5] return = [10, 5]
k = 0 weight = [3] return = [3]
- 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[] lexicographicallyMaximalResultingArray(int[] weight, int k) {
// write your code here
}