Code Room
CodingMediumcod-g1014
Subject Thread pool completion timesLevel Mid–Senior~30 minCommon in Concurrency interviewsIndustries Software development, Technology

Question

A thread pool has `workers` identical worker threads. Tasks are submitted in order; task i has duration durations[i] and is submitted at submit_time times[i] (times is non-decreasing). When a task is submitted, if a worker is free it starts immediately; otherwise it waits in a FIFO queue and starts as soon as a worker frees up. Among queued tasks, the one submitted earlier starts first (ties broken by smaller index). Compute and return a list `finish` where finish[i] is the time task i completes. A task running for d units starting at time s finishes at s + d.

Implement
pool_finish_times(workers: int, times: list[int], durations: list[int]) → list[int]
Examples
in[1,[0,0,0],[5,3,2]]out[5,8,10]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.