Design a Meeting Room Scheduler
🚪 What is a meeting room scheduler? It is the system an office uses to hand out its meeting rooms. Someone asks for a room for a time range and a number of people. The scheduler finds a room that has enough seats and is not already booked for any part of that time, and records the booking. Later the meeting can be cancelled, and anyone can ask which rooms are free.
This problem is asked under several names: "design a meeting scheduler", "book meeting rooms with capacities", "detect conflicting meetings". They are the same design. The core is two small rules, capacity (the room must be big enough) and conflicts (two meetings in one room must not overlap), plus a choice of which room to give. We build that core first, then cover invitees, the earliest free slot and recurring bookings in Extensibility.
Requirements
"Design a meeting room scheduler. There are N rooms with different capacities. Users book a room for a time slot."
That is the whole prompt in most interviews. The open questions are about time, capacity and tie-breaking, and each answer becomes a rule we code against.
Clarifying Questions
You: How is a time slot given? And does a meeting that ends at 10:00 clash with one that starts at 10:00?
Interviewer: A start and an end, as minutes. Back-to-back meetings are fine: a meeting from 9:00 to 10:00 and one from 10:00 to 11:00 can use the same room.
You: Does the user pick the room, or does the system pick one?
Interviewer: The system picks. The user says how many people are coming.
You: If several rooms are big enough and free, which one?
Interviewer: Don't waste big rooms. Give the smallest room that fits. If two rooms have the same size, the one with the lower number.
You: Can a meeting be cancelled? Can it be moved?
Interviewer: Cancelled, yes. Moving is just a cancel plus a new booking for now.
You: Do we check whether the people themselves are free, or only the rooms?
Interviewer: Only rooms. People's calendars are another system. We might talk about it later.
You: Besides booking, what do people ask the system?
Interviewer: Which room a meeting is in, and which rooms are free for a given time and group size, for the booking screen.
You: Several people may book at once from different laptops. Do we care?
Interviewer: Start with one caller. We can come back to it.
The first answer is the most important one in the whole problem. "Back-to-back is fine" means time ranges are half-open: a meeting covers [start, end), its start minute but not its end minute. Get this wrong and every overlap check is off by one.
💡 Interview tip: Say the overlap rule out loud and write it down before any code: two ranges
[s1, e1)and[s2, e2)overlap whens1 < e2 and s2 < e1. It is one line, it covers every case (inside, around, partly before, partly after), and the interviewer will see that you are not going to write four separateifchecks.
Final Requirements
- The office has a fixed set of rooms, each with an id and a capacity.
- A booking asks for a time range
[start, end)and a number of attendees. A range withstart >= endis invalid. - A room can take the booking only if it has at least that many seats and none of its bookings overlaps the range. Back-to-back bookings do not overlap.
- Among the rooms that can take it, the system picks the one with the fewest seats; ties go to the lowest room id. The booking gets a meeting id. If no room can take it, the booking fails.
- A booked meeting can be cancelled, which frees its time in its room. Cancelling an unknown or already-cancelled meeting is an error.
- Anyone can ask which room a meeting is in, and which rooms are free for a range and a group size.
Out of scope
- Checking whether attendees are free (we come back to this in Extensibility).
- Recurring meetings, equipment (projectors, video), and room locations.
- Notifications and invitations.
- Several callers at the same time (also in Extensibility).