Design and Implement a Fair Event Registration Queue
Model a registration queue that preserves arrival order while supporting constant-time registration and arbitrary cancellation plus non-removing top-k reads.
Design and implement the core of a fair event-registration queue. For this exercise, assume one in-memory, single-process event owns an ordered queue of active registrations identified by unique nonempty participant IDs.
register(participantId) appends an absent participant to the tail and explicitly rejects an active duplicate. unregister(participantId) removes any active participant and explicitly reports a missing ID.
topK(k) returns, without removing, up to the earliest k active participant IDs in registration order; a nonpositive k is invalid. A participant who unregisters and later registers again joins the tail with a new fair position.
The single-threaded core must provide O(1) register and unregister and O(k) topK by combining ordered links with direct ID lookup. Keep persistence, capacity limits, priorities, notifications, and multiple events out of scope.
After the core design and implementation, discuss how concurrent callers could preserve the same fairness and atomicity contract.