This question evaluates a candidate's ability to design efficient data structures and algorithms for managing an ordered waitlist with dynamic additions, cancellations, and capacity-based selections, emphasizing performance under high operation counts.
You are implementing the waitlist system for a restaurant. Parties arrive over time, can cancel, and get seated when a table becomes available.
partyId
, a
name
, and a
size
(number of people).
c
becomes available, you must seat the
earliest-arrived
party whose
size <= c
.
Design a data structure / class that supports the following operations efficiently:
addParty(name, size) -> partyId
cancelParty(partyId) -> bool
true
if removed, otherwise
false
.
seatTable(capacity) -> partyId or null
size <= capacity
.
null
if nobody fits.
getPosition(partyId) -> int
-1
.
2 * 10^5
operations.
seatTable
and
getPosition
).