Design a Restaurant Waitlist with Table Assignment, Party Splitting and Fast Cancellation

Quick Overview

Design the data structures behind a restaurant waitlist that hands freed tables to waiting parties using priority queues, can split large parties across tables, keeps table queues balanced and cancels a waiting party quickly. The question also asks for per-operation and amortized complexity.

Design a Restaurant Waitlist with Table Assignment, Party Splitting and Fast Cancellation

Company: Google

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: medium

Interview Round: Technical Screen

Design and implement the core of a restaurant waitlist. Parties of a given size arrive and wait, tables of different capacities become free as diners leave, and the system decides which waiting party gets which table. The interview starts from a basic version that uses a priority queue to find the best seat assignment, then asks how to split a party across tables when splitting is allowed, and how to keep the waitlists balanced so that one large table type does not build up a very long queue. The follow-up: a waiting party cancels before being seated, and the removal must be fast. Finish by stating the complexity of each operation, being explicit about amortized versus worst-case cost. ### Constraints and Clarifications - The restaurant has a fixed set of tables, each with a capacity. A table is free or occupied, and the system is told when an occupied table frees up. - A party fits a table whose capacity is at least the party's size. - The source leaves the meaning of "best assignment" open. Settle it with the questions below and state your policy before writing code. - Assume a single process holding everything in memory. ### Clarifying Questions - What makes an assignment best: the smallest table that fits, the longest-waiting party, or a mix? May a later party take a freed table that an earlier party cannot use? - Should a small party ever be seated at a large table while large parties wait? - When splitting is allowed, is it the party's choice, into how many tables at most, and must the pieces be seated at the same moment? - Does "balanced" mean similar queue lengths per table size, or similar expected waits? - Is cancellation by party id, and can the same id join again later? ### Part 1: Seat parties with a priority queue Define the operations (for example `add_party(party_id, size)` and `table_freed(table_id)`) and implement them so that a freed table goes to the right waiting party, and an arriving party is seated at once when a suitable table is free. ```hint Decide what each queue orders Waiting parties and free tables both change over time. Decide which of them sit in priority queues, what each queue is ordered by, and what happens when the party at the top cannot use the table that just freed. ``` #### What This Part Should Cover - A stated seating policy and the ordering used by each priority queue. - Handling a freed table that the first waiting party does not fit, with the fairness and table-use trade-off. - The cost of each operation. ### Part 2: Split large parties and balance the waitlists Now a party may be split across several tables. How do you choose the split, and how do you keep the waitlists balanced so the queue for the largest tables does not grow very long while smaller tables sit idle? ```hint Split only when it pays Compare how long a large party would wait for one large table with how long it would wait for a set of smaller ones, and check which smaller parties the split would push back. ``` #### What This Part Should Cover - How the split is chosen (number of tables, empty seats) and when the pieces are seated. - A balancing rule based on queue length or expected wait per table size. - The effect of splitting on smaller parties already waiting. ### Part 3: Cancel quickly and state the complexity A waiting party cancels. Remove it quickly, then give the time complexity of every operation, separating amortized from worst-case bounds. ```hint Removing from the middle of a heap A binary heap cannot find an arbitrary entry by id cheaply. Consider whether the entry has to leave the heap at the moment of cancellation. ``` #### What This Part Should Cover - Per-party state that makes cancellation constant time. - How cancelled entries are skipped or cleaned out later, and how memory stays bounded. - An amortized argument stated explicitly, alongside the worst case for a single call. ### What a Strong Answer Covers - A seating policy settled before code, and working code for the core operations. - Consistent bookkeeping: the counts used for balancing stay correct after seating, splitting and cancelling. - Edge cases: a party larger than every table, a cancel for an unknown or already seated party, an id that rejoins, a table reported free twice. - Complexity stated with the amortized reasoning made explicit. ### Follow-up Questions - The host wants to show every waiting party an estimated wait. What would you track to compute it? - How would the design change if several host stations update the same waitlist at the same time? - How would you add reservations for fixed times alongside walk-in parties?

Overview: Design the data structures behind a restaurant waitlist that hands freed tables to waiting parties using priority queues, can split large parties across tables, keeps table queues balanced and cancels a waiting party quickly. The question also asks for per-operation and amortized complexity.

Read the full Google Software Engineer interview experience this question came from

Google logo
Google
Nov 20, 2026
mediumSoftware EngineerTechnical ScreenSoftware Engineering Fundamentals
1
0

Design and implement the core of a restaurant waitlist. Parties of a given size arrive and wait, tables of different capacities become free as diners leave, and the system decides which waiting party gets which table.

The interview starts from a basic version that uses a priority queue to find the best seat assignment, then asks how to split a party across tables when splitting is allowed, and how to keep the waitlists balanced so that one large table type does not build up a very long queue. The follow-up: a waiting party cancels before being seated, and the removal must be fast. Finish by stating the complexity of each operation, being explicit about amortized versus worst-case cost.

Constraints and Clarifications

  • The restaurant has a fixed set of tables, each with a capacity. A table is free or occupied, and the system is told when an occupied table frees up.
  • A party fits a table whose capacity is at least the party's size.
  • The source leaves the meaning of "best assignment" open. Settle it with the questions below and state your policy before writing code.
  • Assume a single process holding everything in memory.

Clarifying Questions Guidance

  • What makes an assignment best: the smallest table that fits, the longest-waiting party, or a mix? May a later party take a freed table that an earlier party cannot use?
  • Should a small party ever be seated at a large table while large parties wait?
  • When splitting is allowed, is it the party's choice, into how many tables at most, and must the pieces be seated at the same moment?
  • Does "balanced" mean similar queue lengths per table size, or similar expected waits?
  • Is cancellation by party id, and can the same id join again later?

Part 1: Seat parties with a priority queue

Define the operations (for example add_party(party_id, size) and table_freed(table_id)) and implement them so that a freed table goes to the right waiting party, and an arriving party is seated at once when a suitable table is free.

What This Part Should Cover Guidance

  • A stated seating policy and the ordering used by each priority queue.
  • Handling a freed table that the first waiting party does not fit, with the fairness and table-use trade-off.
  • The cost of each operation.

Part 2: Split large parties and balance the waitlists

Now a party may be split across several tables. How do you choose the split, and how do you keep the waitlists balanced so the queue for the largest tables does not grow very long while smaller tables sit idle?

What This Part Should Cover Guidance

  • How the split is chosen (number of tables, empty seats) and when the pieces are seated.
  • A balancing rule based on queue length or expected wait per table size.
  • The effect of splitting on smaller parties already waiting.

Part 3: Cancel quickly and state the complexity

A waiting party cancels. Remove it quickly, then give the time complexity of every operation, separating amortized from worst-case bounds.

What This Part Should Cover Guidance

  • Per-party state that makes cancellation constant time.
  • How cancelled entries are skipped or cleaned out later, and how memory stays bounded.
  • An amortized argument stated explicitly, alongside the worst case for a single call.

What a Strong Answer Covers Guidance

  • A seating policy settled before code, and working code for the core operations.
  • Consistent bookkeeping: the counts used for balancing stay correct after seating, splitting and cancelling.
  • Edge cases: a party larger than every table, a cancel for an unknown or already seated party, an id that rejoins, a table reported free twice.
  • Complexity stated with the amortized reasoning made explicit.

Follow-up Questions Guidance

  • The host wants to show every waiting party an estimated wait. What would you track to compute it?
  • How would the design change if several host stations update the same waitlist at the same time?
  • How would you add reservations for fixed times alongside walk-in parties?