Least-loaded task assignment
A thread pool with `workers` worker threads (0..workers-1) processes a queue of tasks one unit of work at a time using a least-loaded assignment policy. Tasks arrive in order with cost costs[i]. Each task is assigned to the worker that currently has the smallest total assigned cost; ties are broken by the smaller worker id. Return a list `load` of length `workers` where load[w] is the total cost assigned to worker w after all tasks are placed.
Implement
assign_loads(workers: int, costs: list[int]) → list[int]Examples
in
[2,[3,1,2,4]]out[7,3]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 25 min
solution.py
InputExpectedGot
[2,[3,1,2,4]][7,3]not run yetsample