Hand Out the Lowest Free Seat Number in a Reservation System

Last updated: November 29, 2026

Quick Overview

Design a seat manager for seats numbered 1 to n. `reserve()` returns the smallest unreserved seat number and marks it taken; `unreserve(s)` frees seat s.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Design a seat manager for seats numbered 1 to n. `reserve()` returns the smallest unreserved seat number and marks it taken; `unreserve(s)` frees seat s.

A small design-a-class question in the style of Google phone screens, framed as booking seats for an on-site event. The interviewer checks that the candidate uses a min-heap of freed seats and avoids a full scan per call.

What the Interviewer Expects
  • Uses a min-heap for available seats
  • Avoids O(n) scans per reserve
  • Optionally uses a lazy counter to avoid heapifying all n seats
  • Defines behavior on invalid calls
  • States per-operation complexity
Key Topics to Cover
Min-Heap
Data Structure Design
Lazy Initialization
Priority Queue
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
  • What if n is 10^9 and most seats are never touched?
  • Support reserving the smallest free seat at or above a given number
  • Make it thread-safe
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
  • Constructor SeatManager(n): seats 1..n all free.
  • reserve(): return and take the smallest free seat. Calls are guaranteed valid (a seat exists).
  • unreserve(s): free a currently reserved seat...
High-Level Design

Seats freed by unreserve can be any numbers, so I need the minimum of a changing set: a min-heap. A naive version heapifies all n seats up front, which is O(n) memory even if only a handful are ever...


Submit Your Answer
Markdown supported