Design a Restaurant Waitlist That Seats the Right Party

Last updated: November 29, 2026

Quick Overview

Implement a waitlist supporting join(party_id, size), leave(party_id), and seat(table_size), where seat removes and returns the party that joined earliest among those whose size fits the table, or None.

Yelp
Coding & Algorithms
Software Engineer
Yelp
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Implement a waitlist supporting join(party_id, size), leave(party_id), and seat(table_size), where seat removes and returns the party that joined earliest among those whose size fits the table, or None.

Yelp Waitlist lets diners join a line remotely and lets hosts seat parties as tables free up. This question checks data structure design under a realistic constraint (party sizes are small integers) and whether you can make leave cheap with lazy deletion instead of scanning a list.

What the Interviewer Expects
  • Clarify fairness: earliest joined party that fits, not best fit
  • Exploit bounded party sizes with one FIFO queue per size
  • Make leave O(1) with lazy deletion and sequence numbers
  • Handle a party that leaves and rejoins without seating the stale entry
  • Analyze cost per operation in terms of max party size
Key Topics to Cover
queues
lazy deletion
hash maps
design a data structure
simulation
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • The host prefers best fit to avoid seating a 2 top at an 8 top. How would you change seat?
  • How would you report a party's current position in line?
  • How would you support quoted wait times per party size?
  • What if party sizes are unbounded?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Operations: join adds a party with size 1..S (S around 20). leave cancels. seat(t) returns the party with the smallest join order among parties with size at most t, removes it, or returns None...

High-Level Design

Keep S deques, one per party size, each in join order, plus a dictionary active from party id to (seq, size). leave just deletes from the dictionary; the deque entry becomes stale and gets skipp...


Submit Your Answer
Markdown supported

Related Questions