Practice/Google/Implement Restaurant Waitlist API
Implement Restaurant Waitlist API
Object Oriented DesignMust
Problem
Design and implement a restaurant table management system that handles a waitlist of customer parties. The system should efficiently manage parties joining the waitlist, leaving the waitlist, and being seated at available tables.
When a table becomes available, the system must seat the first party in the waitlist that can fit at that table. For example, if parties of sizes 8, 4, and 3 are waiting in that order, and a table for 6 becomes available, the party of 4 should be seated (since the party of 8 doesn't fit, but the party of 4 does and comes before the party of 3).
Requirements
- Add Party: Allow a party to join the waitlist with a unique identifier and party size (up to a configurable maximum)
- Remove Party: Allow a party to leave the waitlist at any time before being seated
- Seat Party: When a table becomes available, find and seat the first party in the waitlist that fits at the table (party size ≤ table size)
- Query Waitlist: Provide ability to view the current waitlist state
- Maintain Order: Preserve the order in which parties joined the waitlist (FIFO with size constraints)
Constraints
- Maximum party size: 1 to 20 people (configurable)
- Party IDs are unique positive integers
- Table sizes are positive integers
- The waitlist can contain up to 1000 parties
- Operations should be efficient for typical restaurant scenarios
- A party of size N can be seated at any table of size ≥ N
Examples
Example 1: Basic Operations
`
Operations:
- addParty(1, 4) → true (party of 4 added)
- addParty(2, 2) → true (party of 2 added)
- seatParty(5) → 1 (party 1 seated at table of 5)
- getWaitlist() → [(2, 2)]
Explanation: Party 1 (size 4) fits at the table of 5 and is first in line, so they are seated.
`
Example 2: Party Leaves Waitlist
`
Operations:
- addParty(1, 6) → true
- addParty(2, 3) → true
- addParty(3, 4) → true
- removeParty(1) → true
- seatParty(5) → 2 (party 2 seated)
- getWaitlist() → [(3, 4)]
Explanation: Party 1 leaves, so party 2 is now first. Party 2 (size 3) fits at table of 5.
`
Example 3: Skip Parties That Don't Fit
`
Operations:
- addParty(1, 8) → true
- addParty(2, 7) → true
- addParty(3, 3) → true
- seatParty(6) → 3 (party 3 seated)
- getWaitlist() → [(1, 8), (2, 7)]
Explanation: Parties 1 and 2 don't fit (sizes 8 and 7 > table size 6), but party 3 (size 3) does fit and is seated.
`
Example 4: No Suitable Party
`
Operations:
- addParty(1, 10) → true
- addParty(2, 8) → true
- seatParty(6) → -1 (no party fits)
- getWaitlist() → [(1, 10), (2, 8)]
Explanation: No party in the waitlist fits at a table of size 6.
`