Get Minimum Dock Bays
Learn this problemProblem statement
You are managing operations at a large Amazon warehouse. Loaded trucks arrive at the warehouse sequentially and must be unloaded within a specific timeframe to ensure timely delivery. Your task is to determine the minimum number of dock bays needed to unload all trucks within the given timeframe.
Formally, given a scheduling array truckCargoSize of length n, where each unit in the array represents the amount of time in minutes that a dock bay will take to unload the cargo from the i-th truck, and a second integer maxTurnaroundTime representing the total allowed time to unload all trucks, find the smallest number of dock bays d that will enable you to unload all trucks within maxTurnaroundTime minutes.
Notes:
- As soon as a dock bay becomes available after unloading a truck, it can immediately start processing the next truck.
- It is guaranteed that unloading all trucks is possible with some number of dock bays.
- Only the start times of unloading need to be considered in order, not the finish times.
- Trucks are processed in their given arrival order. With
ddock bays, the trucks are distributed among the bays in arrival order so that each bay's total processing time is the sum of the cargo times of the trucks assigned to it. The overall time to unload all trucks equals the maximum total processing time over allddock bays.
Function
getMinimumDockBays(truckCargoSize: int[], maxTurnaroundTime: long) → intComplete the function getMinimumDockBays in the editor.
getMinimumDockBays has the following parameters:
int truckCargoSize[n]: the time in minutes for the dock bay to unload cargo from thei-th truck.long maxTurnaroundTime: the maximum allowed total unloading time.
Returns
int: the smallest number of dock bays d to unload all the cargo within maxTurnaroundTime minutes.
Examples
Example 1
truckCargoSize = [3, 4, 3, 2, 3]maxTurnaroundTime = 8return = 3Example 2
truckCargoSize = [2, 3, 1]maxTurnaroundTime = 7return = 1Constraints
1 ≤ n ≤ 5 * 10^41 ≤ maxTurnaroundTime ≤ 10^151 ≤ truckCargoSize[i] ≤ min(maxTurnaroundTime, 10^9)
More Amazon problems
- Secure Maximum DeliveriesOA · Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW · Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN · Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN · Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW · Seen Jul 2026
- Maximum System Memory CapacityOA · Seen Jul 2026
- Package Delivery SystemOA · Seen Jul 2026