Automation Pipeline, Part 2: Stage Workers
Learn this problemProblem statement
This is part 2 of a three-part automation-pipeline sequence.
An automation pipeline contains stages that run in the given order. Each stage is represented as [number_of_jobs, job_time, workers]. A stage must finish all of its jobs before the next stage can begin.
Within one stage, its workers process jobs in parallel. Every job is indivisible, takes exactly job_time, and occupies one worker until it finishes. A free worker immediately starts another job from the same stage while jobs remain. A job counts as completed when it finishes at or before time_limit.
Implement calculate_jobs_with_workers and return the total number of jobs completed across the pipeline by the time limit.
Function
calculate_jobs_with_workers(stages: int[][], time_limit: int) → intExamples
Example 1
stages = [[4,3,2],[10,1,1]]time_limit = 14return = 12Two workers finish the first stage's 4 jobs in two rounds, using 6 time units. The second stage then completes 8 of its jobs in the remaining 8 time units, for a total of 12.