Worker heartbeat eviction
A cluster coordinator drops workers that stop sending heartbeats. Every id in worker_ids is distinct, joins at second 0 and counts as last seen at second 0. beats holds heartbeats written as "second|worker" in non decreasing second order, and every heartbeat names a worker on the roster. The coordinator sweeps the roster at the second of each heartbeat, before recording that heartbeat, and once more at final_second, which is never earlier than the last heartbeat. A sweep at second t evicts every live worker whose last seen second is more than timeout seconds before t, so t minus last seen must be greater than timeout and an exact match survives. Within one sweep the coordinator evicts the longest silent worker first, breaking ties by the order the ids appear in worker_ids. Eviction is final, so a heartbeat from an evicted worker is ignored and a heartbeat arriving after its own worker has timed out does not save it. Return the evicted ids in eviction order.
evicted_worker_order(worker_ids: list[str], beats: list[str], timeout: int, final_second: int) → list[str][["w1","w2","w3"],["5|w1","5|w2","12|w1","12|w2"],10,20]out["w3"][["alpha","beta","gamma"],["3|beta","5|alpha"],8,20]out["gamma","beta","alpha"][["w1","w2"],["4|w1","4|w2"],3,4]out["w1","w2"]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.
[["w1","w2","w3"],["5|w1","5|w2","12|w1","12|w2"],10,20]["w3"]not run yetsample[["alpha","beta","gamma"],["3|beta","5|alpha"],8,20]["gamma","beta","alpha"]not run yetsample[["w1","w2"],["4|w1","4|w2"],3,4]["w1","w2"]not run yetsample