Consistent hashing replica preference list
To replicate a key onto `repl` distinct physical nodes, a Dynamo-style coordinator finds the key's position on a consistent-hashing ring (one point per node, FNV-1a hash as in the reference, modulo ring_size) and walks clockwise, collecting the first `repl` DISTINCT nodes encountered (the preference list). Given `nodes`, the `key`, `ring_size`, and `repl`, return the ordered preference list of node ids. If repl exceeds the number of nodes, return all nodes in ring-walk order starting from the key.
Implement
preference_list(nodes: list[str], key: str, ring_size: int, repl: int) → list[str]Examples
in
[["A","B","C","D"],"user:42",1024,3]out["B","C","D"]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.
0:00 of about 28 min
solution.py
InputExpectedGot
[["A","B","C","D"],"user:42",1024,3]["B","C","D"]not run yetsample