FastPrepBounded Service Instance Registry

Bounded Service Instance Registry

Revolut logoRevolut● EasyNEW GRADPHONE SCREEN
Learn

Problem statement

Implement the registration behavior for an in-memory service-instance registry. Process the attempted instance addresses from left to right and return one outcome for each attempt.

  • Return REGISTERED and store an address when it is new and fewer than 10 unique addresses are stored.
  • Return DUPLICATE when the address is already stored, including when the registry is full.
  • Return FULL when the address is new but 10 unique addresses are already stored.

Each result models one atomic register call. In a shared concurrent implementation, the duplicate check, capacity check, and insertion must occur in one critical section.

Function

registerInstances(addresses: String[]) → String[]

Examples

Example 1

addresses = ["192.168.1.1","192.168.1.2","192.168.1.1"]return = ["REGISTERED","REGISTERED","DUPLICATE"]

The repeated address is rejected without consuming capacity.

Example 2

addresses = ["a","b","c","d","e","f","g","h","i","j","k"]return = ["REGISTERED","REGISTERED","REGISTERED","REGISTERED","REGISTERED","REGISTERED","REGISTERED","REGISTERED","REGISTERED","REGISTERED","FULL"]

After ten unique registrations, an eleventh unique address is rejected.

Constraints

  • 0 <= addresses.length <= 100000.
  • Every address has length from 1 to 100.
  • Addresses are case-sensitive opaque strings.

Source note: The source image is a source-neutral excerpt of the author-reported prompt.

More Revolut problems

See Revolut hiring insights
public String[] registerInstances(String[] addresses) {
  // Write your code here.
}
addresses["192.168.1.1","192.168.1.2","192.168.1.1"]
expected["REGISTERED", "REGISTERED", "DUPLICATE"]
Checking account…