← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
Implement a consistent hash ring that can add/remove server nodes and map keys to nodes with minimal key redistribution. The ring is a 32-bit space (0 … 2³²-1). Each physical server is represented by multiple virtual nodes (replicas) to ensure even load distribution. Provide three operations: addNode(nodeId), removeNode(nodeId), and getNode(key). addNode hashes the nodeId into the ring and inserts all of its virtual replicas. removeNode deletes every replica of that node. getNode hashes the key and returns the first node encountered when walking clockwise from that hash position (wrap around if necessary). All operations must run in logarithmic time with respect to the number of virtual nodes.