All problems
Rendezvous Hash Pick
Problem
Choose a node for a key with the rendezvous (highest random weight) hashing scheme.
For each node compute the djb2 hash of the string "node:key" and pick the node with the largest score, breaking ties by the lexicographically smallest node name. The djb2 hash starts at 5381 and updates h = (h * 33 + ord(ch)) mod 2**32.
Return the chosen node, or None for an empty node list.
Hint
Scanning nodes in sorted order with a strict greater-than comparison makes ties deterministic.
Test cases
case 1
in: [["a","b","c"],"x"]
expected: "c"
case 2
in: [["n1","n2","n3"],"user42"]
expected: "n1"
case 3
in: [["only"],"k"]
expected: "only"
case 4
in: [[],"k"]
expected: null
Starter codePython
def rendezvous_hash(nodes, key):
# Your code here
pass4 test cases · run your code against them in the editor