Code Room
CodingEasycod-g1097
Subject Leader election by highest id among alive nodesLevel Entry–Mid~18 minCommon in Distributed systems interviewsIndustries Technology

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.