Bird
Raised Fist0
HLDsystem_design~10 mins

Leader election in HLD - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to identify the leader node in a ring-based election.

HLD
if node_id == [1]:
    leader = True
Drag options to blanks, or click blank then click option'
Amin_id
Bmax_id
Crandom_id
Dcurrent_id
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing the minimum ID as leader
Using a random ID instead of max ID
2fill in blank
medium

Complete the code to send election messages to the next node.

HLD
send_message(to=[1], message='election')
Drag options to blanks, or click blank then click option'
Aprevious_node
Bleader_node
Cnext_node
Drandom_node
Attempts:
3 left
💡 Hint
Common Mistakes
Sending messages to the previous node
Sending messages to a random node
3fill in blank
hard

Fix the error in the condition to check if the current node is the leader.

HLD
if [1] == max_id:
    declare_leader()
Drag options to blanks, or click blank then click option'
Anode_id
Belection_id
Ccurrent_leader
Dleader_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using leader_id which may not be set yet
Using election_id which is for messages
4fill in blank
hard

Fill both blanks to complete the election message handling logic.

HLD
if received_id [1] node_id:
    forward_id = [2]
else:
    forward_id = node_id
Drag options to blanks, or click blank then click option'
A>
B<
Creceived_id
Dnode_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' in comparison
Forwarding node_id instead of received_id when received_id is larger
5fill in blank
hard

Fill all three blanks to complete the leader announcement broadcast.

HLD
for node in [1]:
    send_message(to=node, message=[2])
leader = [3]
Drag options to blanks, or click blank then click option'
Anetwork_nodes
B'leader_elected'
CTrue
DFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Sending message to only one node
Setting leader to False after election