Bully leader election
Your task
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.
Examples
elect_leader(nodes: list[int], events: list[list]) -> intExample 1
Input
elect_leader([1, 2, 3], [["fail", 3]])Output
2