Problem · Array
Automation Pipeline, Part 3: Stage Duration
Learn this problemProblem statement
This is part 3 of a three-part automation-pipeline sequence.
A single pipeline stage contains jobs whose processing times appear in job_durations. All num_workers workers are free at time 0.
Consider the jobs in array order. Assign each job to a worker that becomes free earliest, then make that worker unavailable for the job's full duration. Each job is indivisible, and each worker processes at most one job at a time.
Implement calculate_stage_duration and return the time when every job has finished. Return 0 when job_durations is empty.
Function
calculate_stage_duration(job_durations: int[], num_workers: int) → intExamples
Example 1
job_durations = [5,2,10,4,8]num_workers = 2return = 17The successive worker availability times are [5,0], [5,2], [5,12], [9,12], and [17,12]. All jobs finish at time 17.
Example 2
job_durations = []num_workers = 2return = 0There are no jobs to schedule, so the stage has duration 0.