0
0
HLDsystem_design~10 mins

Consistent hashing 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 define the hash ring size in consistent hashing.

HLD
hash_ring_size = 2[1]32
Drag options to blanks, or click blank then click option'
A*
B//
C**
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using multiplication '*' instead of exponentiation '**'.
Using integer division '//' which truncates the value.
2fill in blank
medium

Complete the code to find the next node clockwise on the hash ring.

HLD
next_node = sorted_nodes[bisect.bisect_right(sorted_nodes, key_hash) [1] len(sorted_nodes)]
Drag options to blanks, or click blank then click option'
A-
B+
C//
D%
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition '+' without modulo causes index errors.
Using integer division '//' which is not suitable here.
3fill in blank
hard

Fix the error in the code to correctly add virtual nodes to the hash ring.

HLD
for i in range(num_virtual_nodes):
    virtual_node_key = f"{node}-VN[1]"
    hash_value = hash_function(virtual_node_key)
    hash_ring[hash_value] = node
Drag options to blanks, or click blank then click option'
Ai
Bnode
Cnum_virtual_nodes
Dhash_value
Attempts:
3 left
💡 Hint
Common Mistakes
Using the node name repeatedly without index causes key collisions.
Using hash_value inside the string causes errors.
4fill in blank
hard

Fill both blanks to complete the code that finds the responsible node for a given key.

HLD
key_hash = hash_function(key)
index = bisect.bisect_right(sorted_hashes, key_hash) [1] len(sorted_hashes)
responsible_node = hash_ring[sorted_hashes[index [2]]]
Drag options to blanks, or click blank then click option'
A%
B+
C-
D//
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition '+' instead of modulo causes index errors.
Using integer division '//' is incorrect here.
5fill in blank
hard

Fill both blanks to complete the code that reassigns keys when a node is removed.

HLD
for key in keys_to_reassign:
    key_hash = hash_function(key)
    new_index = bisect.bisect_right(sorted_hashes, key_hash) [1] len(sorted_hashes)
    new_node = hash_ring[sorted_hashes[new_index [2]]]
    key_node_map[key] = new_node
Drag options to blanks, or click blank then click option'
A%
B+
C-
Attempts:
3 left
💡 Hint
Common Mistakes
Adding '+' instead of modulo causes errors.
Adding extra characters after assignment causes syntax errors.