Bounded Service Instance Registry
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
REGISTEREDand store an address when it is new and fewer than 10 unique addresses are stored. - Return
DUPLICATEwhen the address is already stored, including when the registry is full. - Return
FULLwhen 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
1to100. - Addresses are case-sensitive opaque strings.
Source note: The source image is a source-neutral excerpt of the author-reported prompt.