Code RoomBully leader election
EasyPrep Room Coding #264

Bully leader election

CodingDistributed systemsEntry–Mid~18 min

A cluster elects a leader using the bully rule: the live node with the highest id wins. Node ids are integers. You are given the initial set of node ids `nodes` and a list of events, each ['fail', id] (the node crashes and is no longer eligible) or ['recover', id] (the node rejoins and is eligible again; it may be an id not in the original set). After applying all events in order, return the id of the current leader (the highest-id node that is currently alive), or -1 if no node is alive.

Implement
elect_leader(nodes: list[int], events: list[list]) → int
Examples
in[[1,2,3],[["fail",3]]]out2
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
[[1,2,3],[["fail",3]]]2not run yetsample