Code RoomBuild agent work stealing
EasyPrep Room Coding #4842

Build agent work stealing

CodingAlgorithms & data structuresEntry–Mid~18 min

A build farm gives every agent its own pile of queued steps, and an idle agent helps out a busy one. workers lists the agent ids in roster order. events replays what happened, each line either "agent|push|step", meaning that agent queued a step on its own pile, or "agent|run", meaning that agent went looking for work. A running agent takes the newest step off its own pile. When its own pile is empty it takes the oldest step from the pile of the first agent in roster order, other than itself, whose pile is not empty. When every pile is empty the run does nothing. Step ids are distinct and each is queued once. Return the ids of the steps that ran on an agent other than the one that queued them, in the order they ran, or an empty list when nothing was taken across.

Implement
stolen_task_order(workers: list[str], events: list[str]) → list[str]
Examples
in[["w1","w2"],["w1|push|a","w1|push|b","w2|run","w1|run"]]out["a"]
in[["w1","w2"],["w1|push|a","w1|push|b","w1|run","w1|run"]]out[]
in[["w1","w2","w3"],["w2|push|t1","w3|push|t2","w1|run","w1|run","w1|run"]]out["t1","t2"]
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 18 min
InputExpectedGot
[["w1","w2"],["w1|push|a","w1|push|b","w2|run","w1|run"]]["a"]not run yetsample
[["w1","w2"],["w1|push|a","w1|push|b","w1|run","w1|run"]][]not run yetsample
[["w1","w2","w3"],["w2|push|t1","w3|push|t2","w1|run","w1|run","w1|run"]]["t1","t2"]not run yetsample