FastPrepFastPrep
Problem Brief

Get Minimum Dock Bays

NEW GRADOA
See Amazon online assessment and hiring insights

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 ith truck, and a second integer, maxTurnaroundTime, representing the total allowed time to unload 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.
  • Function Description

    Complete the function getMinimumDockBays in the editor.

    getMinimumDockBays has the following parameters:

    1. int truckCargoSize[n]: the time in minutes for the dock bay to unload cargo from the ith truck
    2. 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.

    💙 Many thanks to the incredible friend who shared this source!

    1Example 1

    Input
    truckCargoSize = [3, 4, 3, 2, 3], maxTurnaroundTime = 8
    Output
    3
    Explanation
    Example 1 illustration
    Attemping with two dock bays (d = 2): Truck Processing Timeline for 2 Dock1 Bays: With two dock bays, all trucks unloaded in 9 minutes, which exceeds the maxTurnaroundTime of 8 minutes: Attempting with three dock bays (d = 3): With three dock bays, all trucks are unloaded in 6 minutes, which is within the maxTurnaroundTime of 8 minutes. So, the minimum number of dock bays required to unload all trucks within 8 minutes is 3.

    2Example 2

    Input
    truckCargoSize = [2, 3, 1], maxTurnaroundTime = 7
    Output
    1
    Explanation
    With only one dock bay, all trucks can be unloaded in 2 + 1 = 3 = 6 minutes, which is within the maxTurnaroundTime of 7 minutes.

    Constraints

    Limits and guarantees your solution can rely on.

    • 1 ≤ n ≤ 5 * 10^4
    • 1 ≤ maxTurnaroundTime ≤ 10^15 (looks like 15 to me..)
    • 1 ≤ truckCargoSize[i] ≤ min (maxTurnaroundTime 10^9)
    public int getMinimumDockBays(int[] truckCargoSize, long maxTurnaroundTime) {
      // write your code here
    }
    
    Input

    truckCargoSize

    [3, 4, 3, 2, 3]

    maxTurnaroundTime

    8

    Output

    3

    Sign in to submit your solution.