RSVP waitlist desk
MediumOnline Assessment
Track RSVPs for a venue-limited dinner and report who is in, who is waiting and who is undecided.
The venue has capacity seats. Replies arrive in order as [guest, answer, plus_ones] with answer one of "yes", "no", "maybe". A guest's party is the guest plus plus_ones people, so it needs 1 + plus_ones seats; for "no" and "maybe" the plus_ones value is ignored. Parties are never split.
Handle each reply as follows:
- yes from a new guest (or one whose last answer was
noormaybe): the party is seated if it fits in the free seats right now, otherwise it joins the back of the waitlist. - yes from a seated guest changes the party size: a smaller or equal party frees its seats; a larger party grows only if the extra seats are free right now, otherwise the guest keeps the party they already had.
- yes from a waitlisted guest updates the party size, and the guest keeps their place in the waitlist.
- no removes the guest from the seats or the waitlist (and from the maybes).
- maybe also removes the guest from the seats or the waitlist, and records them as undecided.
After every reply, while seats are free, seat the earliest waitlisted party that fits in the free seats (a party that does not fit is skipped, not waited for), and repeat until no waitlisted party fits.
Input: capacity, an integer, and replies, a list of [guest, answer, plus_ones].
Output: [seated, waitlist, undecided]: the seated guests sorted alphabetically (plain code point order), the waitlisted guests in waitlist order (front first), and the guests whose latest answer is maybe, sorted alphabetically.
Example 1
- Input:
- [5,[["Ann","yes",0],["Bob","yes",3],["Cat","yes",1],["Dan","yes",0],["Ann","no",0]]]
- Output:
- [["Bob","Dan"],["Cat"],[]]
- Explanation
- Ann (1 seat) and Bob (4 seats) fill all 5 seats. Cat (2) and Dan (1) both join the waitlist in that order. When Ann cancels, 1 seat is free: Cat's party of 2 does not fit, but Dan's party of 1 does, so Dan is seated and Cat keeps waiting.
Example 2
- Input:
- [4,[["Eve","yes",1],["Fay","maybe",0],["Gus","yes",0],["Hal","yes",1],["Eve","yes",0],["Fay","yes",0],["Gus","yes",2],["Ivy","maybe",5]]]
- Output:
- [["Eve","Gus","Hal"],["Fay"],["Ivy"]]
- Explanation
- Eve brings one guest (2 seats), Fay is a maybe, Gus takes 1 seat and Hal's party of 2 does not fit (1 seat free), so Hal waits. Eve then shrinks her party to 1, freeing a seat, and Hal is seated. Fay now says yes but no seat is free, so she goes to the waitlist and is no longer a maybe. Gus asks to grow to 3 seats, but no extra seats are free, so he keeps 1. Ivy's maybe is recorded.
Example 3
- Input:
- [3,[["Jo","yes",1],["Kim","yes",2],["Lee","yes",0],["Kim","yes",0],["Jo","no",0],["Mo","yes",0],["Nat","yes",0],["Lee","maybe",0],["Jo","yes",0]]]
- Output:
- [["Kim","Mo","Nat"],["Jo"],["Lee"]]
- Explanation
- Jo (2 seats) is seated; Kim's party of 3 does not fit and waits. Lee needs 1 seat and fits, so he is seated even though someone is waiting. Kim changes to a party of 1 and keeps their place, but still no seat is free. Jo cancels, which frees 2 seats and seats Kim. Mo takes the last seat; Nat has to wait. Lee turns maybe, freeing a seat for Nat. Finally Jo says yes again; the venue is full, so Jo joins the back of the waitlist.
Constraints
1 <= capacity <= 1000 <= replies.length <= 120- Guest names are 1 to 12 letters;
0 <= plus_ones <= 10 - A party can be larger than
capacity; it then waits forever