Lexicographically Maximal Resulting Array
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
1Example 1
