Fix the result collector in a worker pool
Your task
An agent's PR moves your job runner to a worker pool. Its version started a goroutine per job and wrote every result into one shared map, so a repeated job id silently overwrote an earlier result. You model what a correct pool should produce, so the PR can be checked against it.
An assistant wrote schedule_pool_results(job_ids, durations, workers). It is in the editor. It has a bug. Find it and fix it.
Input and output:
job_ids,durations: the jobs in submission order. Jobihas idjob_ids[i]and takesdurations[i]time units.workers: the number of worker slots.- Return one string per job that ran,
"<job_id>|<finish_time>".
Rules the tests check:
- If the two lists differ in length, use only as many jobs as the shorter list has.
- A
workersvalue below 1 counts as 1. A negative duration counts as 0. - Every slot is free at time 0. Take the jobs in submission order. Each job goes to the slot that is free earliest, the lowest slot number on a tie. It starts when that slot is free and finishes
durationlater, and the slot is busy until then. - A job whose id already appeared earlier in the list is refused: it does not run and takes no slot time.
- Sort the output by job id, in ascending order by plain string comparison.
Examples
schedule_pool_results(job_ids: list[str], durations: list[int], workers: int) -> list[str]Example 1
Input
schedule_pool_results(["a", "b", "c"], [3, 1, 2], 2)Output
["a|3", "b|1", "c|3"]Example 2
Input
schedule_pool_results(["j2", "j1"], [5, 5], 1)Output
["j1|10", "j2|5"]Example 3
Input
schedule_pool_results(["a", "a", "b"], [2, 7, 1], 3)Output
["a|2", "b|1"]