AMAZON Coding Question – Solved

5 Live
To be efficient, Amazon must optimally distribute parcels among their delivery agents. Initially, there are n agents, and the number of parcels assigned to the i-th agent is initialParcels[i]. There are additionalParcels parcels that also need to be shipped. The additional parcels should be assigned such that the maximum number of parcels assigned to any one agent is minimized. Given an integer array, initialParcels, and an integer, additionalParcels, find the minimum possible value of the maximum number of parcels any agent must deliver. Example Suppose n = 5, initialParcels = [7, 5, 1, 9, 1], and additionalParcels = 25. An optimal assignment is shown: Initial Parcels | Additional Parcels | Total Parcels 7 | 3 | 10 5 | 5 | 10 1 | 9 | 10 9 | 1 | 10 1 | 7 | 8 There are other possible optimal assignments, but the minimum value of the maximum number of parcels any agent will deliver is 10. Function Description Complete the function minimizeMaxParcelLoad in the editor below. minimizeMaxParcelLoad takes the following arguments: int initialParcels[n]: the initial number of parcels assigned to the agents long int additionalParcels: the additional parcels to be assigned Returns long int: the minimum possible value of the maximum number of parcels an agent must deliver Constraints Β· 1 ≀ n ≀ 10^5 Β· 1 ≀ additionalParcels ≀ 10^15 Β· 1 ≀ initialParcels[i] ≀ 10^9 Sample Input initialParcels = [1, 2, 3] additionalParcels = 3 Sample Output 3 Explanation It is optimal to assign 2 additional parcels to the first agent and 1 additional parcel to the second agent. Finally, each agent will have to deliver 3 parcels.

Asked in: AMAZON

Image of the Question

Question Image Question Image Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| Stacey is coordinating a beach clean-up event with her university's Women in ST… |
| Perform a series of operations on a given array of integers. Each operation con… |
| Data scientists at Amazon are working on a utility for detecting similar passwo… |
| The Amazon warehouse receives a multitude of packages every day, each assigned … |
| As an operations engineer at Amazon, you are responsible for organizing the dis… |
| Amazon Books is a retail store that sells the newly launched novel "The Story o… |