This question evaluates object-oriented design and data-structure competency—modeling a FIFO waitlist API, managing unique party identifiers and edge cases, and reasoning about time and space complexity; it falls under the Software Engineering Fundamentals domain with emphasis on OOP and algorithms.
Design a waitlist management component (e.g., for a restaurant or event) that maintains FIFO order for parties as they join a waitlist.
Implement a class (or set of classes) with APIs similar to:
add(partyId, partySize, metadata) -> void
: Add a party to the end of the waitlist.
cancel(partyId) -> bool
: Remove a party if they are currently waiting.
nextParty() -> Party | null
: Return (and remove) the next eligible party to be seated.
peekNext() -> Party | null
: Return the next party without removing.
position(partyId) -> int | null
: Return the party’s current position (optional follow-up).
partyId
is unique.
position(partyId)
efficiently?