Three-Stage Labeling Workforce Simulation
Problem statement
Customer tasks pass through sequential stages L0 → L1 → L2. A task is complete after its L2 work finishes.
Given task IDs, worker IDs, and each worker's positive integer duration per stage, simulate the process.
- A task stage has at most one assigned worker, and a worker handles at most one stage at a time.
- A worker may never work on the same task twice, even at another stage.
- At a timestamp, process all completions in worker input order, then assign idle workers in worker input order.
- For an idle worker, greedily choose the first task in task input order whose current stage is ready, unassigned, and not previously handled by that worker.
- After assignments, jump to the next completion timestamp.
Return an event log. Each line is time ASSIGN worker task Ls or time COMPLETE worker task Ls. Append TOTAL time after all tasks finish.
Function
simulateLabelingWorkforce(tasks: String[], workers: String[], durations: int[]) → String[]Examples
Example 1
tasks = ["A"]workers = ["X","Y","Z"]durations = [1,1,1]return = ["0 ASSIGN X A L0","1 COMPLETE X A L0","1 ASSIGN Y A L1","2 COMPLETE Y A L1","2 ASSIGN Z A L2","3 COMPLETE Z A L2","TOTAL 3"]The no-repeat rule forces three different workers across the three stages.
Example 2
tasks = ["A","B"]workers = ["X","Y","Z"]durations = [1,1,1]return = ["0 ASSIGN X A L0","0 ASSIGN Y B L0","1 COMPLETE X A L0","1 COMPLETE Y B L0","1 ASSIGN X B L1","1 ASSIGN Y A L1","2 COMPLETE X B L1","2 COMPLETE Y A L1","2 ASSIGN Z A L2","3 COMPLETE Z A L2","3 ASSIGN Z B L2","4 COMPLETE Z B L2","TOTAL 4"]This is one deterministic greedy schedule allowed by the original prompt.
Example 3
tasks = ["A"]workers = ["X","Y","Z"]durations = [2,1,3]return = ["0 ASSIGN X A L0","2 COMPLETE X A L0","2 ASSIGN Y A L1","3 COMPLETE Y A L1","3 ASSIGN Z A L2","6 COMPLETE Z A L2","TOTAL 6"]The follow-up's worker-specific durations determine the completion timestamps.
Constraints
1 <= tasks.length <= 1000.3 <= workers.length <= 1000.workers.length == durations.length.- Task and worker IDs are unique nonempty alphanumeric strings.
1 <= durations[i] <= 1000000.- The stated constraints guarantee the greedy simulation can finish.