FastPrepMaintain a Consistent-Hashing Ring
Problems/Maintain a Consistent-Hashing Ring

Maintain a Consistent-Hashing Ring

Cohesity logoCohesity● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Cohesity onsite interview. The report asks for a consistent-hashing implementation but leaves out the API, the hash function, the operations on members, and the ring limits. Our version gives precomputed positions and a simple ring interface. It is about 65% the same as the reported question.

Keep track of the nodes in a consistent-hashing ring and which node owns each key. Positions increase clockwise, and the last position wraps back to the first. The input gives the integer hash positions. You do not need to write a hash function.

The ring starts empty. Process the matching arrays operations and positions from left to right. At index i, apply exactly one operation:

  • ADD: add a node at positions[i]. A node is identified by its position and has exactly one ring point. Adding an existing position has no effect.
  • REMOVE: remove the node at positions[i]. Removing a missing node has no effect.
  • LOOKUP: interpret positions[i] as a key position. Its owner is the active node with the smallest position greater than or equal to that key. If there is no such node, wrap to the active node with the smallest position. If the ring is empty, return -1 for this lookup.

Return an integer array containing only the LOOKUP results in the order of the lookups. Do not change either input array. Each operation uses the nodes present after the earlier operations. A node added later is not yet available.

Function

runConsistentHashRing(operations: String[], positions: int[]) → int[]

Examples

Example 1

operations = ["ADD","ADD","LOOKUP","LOOKUP","LOOKUP"]positions = [10,30,10,11,35]return = [10,30,10]

Position 10 owns its exact key. The next clockwise node after 11 is 30, and 35 wraps to 10.

Example 2

operations = ["LOOKUP","ADD","ADD","REMOVE","LOOKUP","REMOVE","ADD","LOOKUP"]positions = [5,20,20,20,0,20,0,1]return = [-1,-1,0]

The first lookup finds an empty ring. Adding node 20 twice still creates one member, so one removal empties the ring. Removing that missing member does nothing. The final lookup wraps to node 0.

Example 3

operations = ["ADD","ADD","LOOKUP","ADD","LOOKUP","REMOVE","LOOKUP"]positions = [10,30,20,25,20,25,20]return = [30,25,30]

The key at 20 is first assigned to 30, then to newly added node 25, and back to 30 after node 25 is removed.

Constraints

  • 0 <= operations.length <= 100000.
  • positions.length == operations.length.
  • Every operation is ADD, REMOVE, or LOOKUP.
  • 0 <= positions[i] <= 1000000000.
  • Positions and the returned node identifiers are integers.

More Cohesity interview questions

  • LRU Key-Value Cache OperationsPHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Maintain a Consistent-Hashing RingApple · PHONE SCREENApple interview questions
  • Transaction Event StoreCapital One · ONSITE INTERVIEWCapital One interview questions
  • Out-of-Order Logger Rate LimiterGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Dynamic Weighted SamplingCitadel · ONSITE INTERVIEWCitadel interview questions
  • Top K Pins with Insert and QueryPinterest · PHONE SCREENPinterest interview questions
  • Subscription and Usage-Based Billing CalculatorStripe · OAStripe interview questions
  • Time Map with Sum and AverageConfluent · PHONE SCREENConfluent interview questions
  • Structured Log Stream with QueriesOpenAI · PHONE SCREENOpenAI interview questions
  • Choose ContainersIMC Trading · OAIMC Trading interview questions
  • Interview Slot BookingTrueFoundry · PHONE SCREEN
See Cohesity hiring insights
Saved
class Solution {
    public int[] runConsistentHashRing(String[] operations, int[] positions) {
        // Write your code here.
    }

}
Checking account…