Amazon Coding Question – Solved

9 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

| You are given a board of size M Γ— N where each cell can be either empty ('O') o… |
| Undirected Coloured Graph Shortest Path You are given an undirected weight… |
| Village Voyage A computer game "Village Voyage" has N villages (labeled 1 to… |
| Academic Decathlon Students are being selected for an academic decathlon tea… |
| Sum of Arrays Given two arrays each of length n, arr1 and arr2, in one opera… |
| Count Swaps During Custom Sorting Analyze the efficiency of the following so… |