Data Engineer • Junior-Level
Data Engineer • Junior-Level
High QualityInterview Summary
I interviewed with Google and encountered a data structure design problem involving a restaurant waiting list. The task was to support customer groups joining and leaving the queue while efficiently seating the earliest-arriving group that could fit at an available table. I approached the problem using size-based buckets, insertion-ordered dictionaries, and monotonically increasing tickets to balance arrival order with efficient lookups and deletions.
Interview Details
Coding: Restaurant Waiting List System
Question 1 — Design a Restaurant WaitingList
The interviewer asked me to design a restaurant waiting list system that manages customer groups waiting for available tables. Each group had two attributes:
group_id: A unique identifier for the group.group_size: The number of people in the group.
The system needed to support three core operations:
- join(group_id, group_size): Add a group to the waiting list.
- leave(group_id): Remove a group from the waiting list.
- serve(table_size): Find and remove the earliest-arriving group whose size does not exceed the available table capacity.
The most important requirement was the seating policy. When a table became available, I needed to choose the group that had been waiting the longest among all groups that could fit at the table. For example, if a table had four seats, a group of five would not qualify, even if it had arrived before everyone else.
However, among all groups containing four or fewer people, the earliest arrival had to be selected. If no group could fit, the operation should return None.
Question 2 — Support Efficient Seating and Arbitrary Removal
The main challenge was finding a data structure that could efficiently support both arrival order and group-size constraints. A simple FIFO queue could preserve arrival order, but it would not efficiently support all the required operations. For example, if the group at the front of the queue was too large for the available table, I would need to search further into the queue.
In the worst case, that could require scanning the entire waiting list. Removing a group from the middle of a standard queue would also be inefficient. I therefore needed a design that supported both:
- Finding the earliest eligible group for a given table capacity.
- Removing a group directly using its
group_id.
Question 3 — Design Size-Based Buckets and Arrival Tickets
I proposed organizing the waiting list using three structures.
-
Global Waitlist
I used a dictionary called
waitlistto map eachgroup_idto itsgroup_size. This allowed me to check whether a group was already waiting and determine its size when it needed to leave. -
Size-Based Queues
I used a structure called
size_queuesto organize groups by their sizes. Each group size had its own insertion-ordered dictionary. Within each bucket, the dictionary mapped a group's ID to its arrival ticket. For example, all groups containing two people were stored in the same bucket, ordered by when they joined. -
Monotonically Increasing Ticket
Unlock Full Details
Create a free account to unlock this interview experience report.