FastPrepGet Minimum Dock Bays
Problems/Get Minimum Dock Bays

Get Minimum Dock Bays

Amazon logoAmazon● MediumNEW GRADOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem 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 d dock 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 all d dock bays.

Function

getMinimumDockBays(truckCargoSize: int[], maxTurnaroundTime: long) → int

Complete 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 the i-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 = 3

Attempting with two dock bays (d = 2): the trucks are distributed in arrival order between the two bays. Dock bay 1 unloads trucks 1, 3, and 5 (3 + 3 + 3 = 9 minutes) and dock bay 2 unloads trucks 2 and 4 (4 + 2 = 6 minutes). All trucks are unloaded in 9 minutes, which exceeds the maxTurnaroundTime of 8 minutes. Attempting with three dock bays (d = 3): the bays finish in 5, 7, and 3 minutes respectively, so all trucks are unloaded in 7 minutes, which is within the maxTurnaroundTime of 8 minutes. Therefore, the minimum number of dock bays required is 3.

Example 2

truckCargoSize = [2, 3, 1]maxTurnaroundTime = 7return = 1

With only one dock bay, all trucks can be unloaded in 2 + 3 + 1 = 6 minutes, which is within the maxTurnaroundTime of 7 minutes. Therefore, the minimum number of dock bays required is 1.

Constraints

  • 1 ≤ n ≤ 5 * 10^4
  • 1 ≤ maxTurnaroundTime ≤ 10^15
  • 1 ≤ truckCargoSize[i] ≤ min(maxTurnaroundTime, 10^9)

More Amazon interview questions

  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Maximal SquareONSITE INTERVIEW · Seen Nov 2026
  • Serialize and Deserialize a Binary TreeONSITE INTERVIEW · Seen Nov 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Diagonal Traversal of a Binary TreeONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Spread Through a GridPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Consistent-Hash Packet RouterPHONE SCREEN · Seen Nov 2026
  • Count Connected ComponentsPHONE SCREEN · Seen Nov 2026
  • Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026

Similar questions at other companies

  • Finish Ordered CPU Tasks with the Fewest CPUsGoogle · PHONE SCREENGoogle interview questions
  • Running Medians and PercentilesStackAdapt · PHONE SCREENStackAdapt interview questions
  • Minimum Cost to Merge Values into OnePayPal · OAPayPal interview questions
  • Bank Accounts with Balance HistoryMeta · OAMeta interview questions
  • Maximum Interactive Team SizeMicrosoft · OAMicrosoft interview questions
  • Maximum ScoreNVIDIA · OANVIDIA interview questions
  • Minimum Meeting RoomsJP Morgan Chase · OAJP Morgan Chase interview questions
  • Index of the Maximum After Left RotationsChubb · OAChubb interview questions
  • Team FormationDoorDash · OADoorDash interview questions
  • Rolling MetricsAkuna Capital · OAAkuna Capital interview questions

Interview reports that mention this question

  • Amazon New Grad OA Problems: Every Task We Have (Part 3 of 5)

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE Onsite Interview Questions: 9 Experiences
  • Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
  • Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
  • Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)
See Amazon hiring insights
Saved
class Solution {
    public int getMinimumDockBays(int[] truckCargoSize, long maxTurnaroundTime) {
      // write your code here
    }

}
Checking account…