Problem · Array
Automation Pipeline, Part 1: Single Worker
Learn this problemProblem statement
This is part 1 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]. A stage must finish all of its jobs before the next stage can begin.
The pipeline has one worker. The worker processes one job at a time, and each job in a stage takes exactly that stage's job_time. A job counts as completed when it finishes at or before time_limit.
Implement calculate_jobs_completed and return the total number of jobs completed across the pipeline by the time limit.
Function
calculate_jobs_completed(stages: int[][], time_limit: int) → intExamples
Example 1
stages = [[4,3],[10,1]]time_limit = 14return = 6The first stage completes 4 jobs in 12 time units. The remaining 2 time units complete 2 jobs from the second stage, for a total of 6.