Code RoomMinimum worker pool size
HardPrep Room Coding #4922

Minimum worker pool size

CodingAlgorithms & data structuresSenior–Staff~38 min

A transcoder cuts an upload into fixed length chunks and hands them to a pool of identical workers. arrival_seconds lists the second each chunk reached the queue, sorted ascending and possibly with repeats, and every chunk occupies one worker for exactly job_seconds. Chunks leave the queue strictly in arrival order, and each one starts the moment a worker frees up. A chunk may wait at most wait_cap seconds between arriving and starting. Return the smallest pool size that holds every chunk inside that limit, and 0 when there are no chunks at all. Counting the chunks that land inside a single stretch of wait_cap plus job_seconds and dividing gives the wrong pool size, so the queue itself has to be modelled.

Implement
pool_size_for_wait_cap(arrival_seconds: list[int], job_seconds: int, wait_cap: int) → int
Examples
in[[0,0,0,5,5],4,3]out3
in[[0,10,20,30],7,0]out1
in[[0,0,0,0,0,0,0,0,0],10,15]out5
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.

0:00 of about 38 min
InputExpectedGot
[[0,0,0,5,5],4,3]3not run yetsample
[[0,10,20,30],7,0]1not run yetsample
[[0,0,0,0,0,0,0,0,0],10,15]5not run yetsample