Minimum Execution Time
Learn this problemProblem statement
Amazon's "UltraCompute" service receives an array of n job fragments. Each fragment's size is recorded in jobSize[i] for 0 ≤ i < n. At the same time, the fleet has m worker instances whose maximum throughputs are throughput[j] for 0 ≤ j < m.
A worker finishes a fragment in exactly 1 second if jobSize ≤ throughput; otherwise it cannot run that fragment.
Each worker can process at most one fragment per second. If a worker is assigned multiple fragments, there is a mandatory 1-second cooldown pause between completing one fragment and starting the next. Different workers may process different fragments in parallel.
Your task is to compute the minimum number of seconds needed to finish all fragments, or return -1 if at least one fragment is too large for every worker.
Function
minimumExecutionTime(jobSize: int[], throughput: int[]) → intComplete the function minimumExecutionTime in the editor below.
Function Parameters
int jobSize[n]: size of each fragmentint throughput[m]: capacity of each worker
Returns
int: minimum seconds to finish all fragments, or -1
Examples
Example 1
jobSize = [2, 5, 3]throughput = [6, 2, 4]return = 1Assign fragment 5 to the 6-unit worker, fragment 2 to the 2-unit worker, and fragment 3 to the 4-unit worker. All three finish in the same second, so the minimum total time is 1.
Example 2
jobSize = [2, 5, 8]throughput = [6, 7, 4]return = -1The largest fragment has size 8, but the highest worker throughput is 7. That fragment is too large for every worker, so the answer is -1.
Source note (June 28, 2026): The original source image did not include the output for this example. FastPrep worked it out from the problem statement and the given input. If you have the original output or notice something wrong, please let us know and we'll fix it. If we find a fuller source later, we'll come back and update this too. 🦦
Constraints
1 ≤ n, m ≤ 2 * 10^51 ≤ jobSize[i], throughput[j] ≤ 10^9
More Amazon problems
- Resolve Task DependenciesONSITE INTERVIEW · Seen Jul 2026
- Shortest Distance on a Circular Bus RouteOA · Seen Jul 2026
- Longest Increasing Subsequence With Bounded Adjacent DifferenceONSITE INTERVIEW · Seen Jul 2026
- Search in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Jul 2026
- Sliding Window MaximumONSITE INTERVIEW · Seen Jul 2026
- Merge IntervalsOA · Seen Jul 2026
- Sort Bug Report FrequenciesOA · Seen Jul 2026
- Drone Delivery RouteOA · Seen Jul 2026