Amazon Coding Question – Solved

7 Live
FindMaximumWeights Amazon's fulfillment centers handle packages of various weights, and they need to optimize their sorting process. Given an array weight that denotes the weights of n packages, the goal is to create the lexicographically maximal resulting array sorted in non-increasing order using the following operations: 1. Discard the first package from the current weight array. 2. Add the first element to the resulting array, then remove it along with the next k (a fixed constant) elements from the current array. 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.

Asked in: Amazon

Image of the Question

Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| Given an n x m grid, where rows are numbered from 7 to n and columns from 1 to … |
| There are 'N' coders standing in a line, where i denotes the ith position of a … |
| A birthday party was attended by N number of kids, and each kid was given a uni… |
| Given a matrix of size m * n, where m denotes the number of rows (starting with… |
| A traveler is traveling from the city of Zeta to Omega. He starts with X amount… |
| As an operations engineer at Amazon, you are responsible for organizing the dis… |