Designing a Meeting Scheduler

Difficulty: Intermediate Patterns: Strategy, Observer, State Asked at: Google, Microsoft, Amazon, Atlassian


Book a meeting with four people and a room. The user-facing surface is a week grid and a Save button, which is exactly why this problem gets handed out: it looks like CRUD. Most candidates write a Meeting class with a start, an end and a list of attendees in the first four minutes, feel good about it, and then discover that every requirement worth marks is about time rather than about storage.

Three things are genuinely hard here, and they fail in three different ways. Conflict detection fails on correctness before it fails on speed: the overlap predicate is a coin flip most people get wrong, and the obvious loop over every existing meeting is O(n) on every booking attempt. Finding a time that suits five people fails because it is not a search over candidate slots at all, however naturally the phrase “find a free slot” suggests scanning one. It is a merge of busy ranges, and the people being merged live in different time zones with different working hours, some of whom you do not actually need. Recurrence fails because “every Tuesday at 10:00, forever” has no row count, so a design that writes occurrences into a table has already lost, and the clock going back an hour in October will quietly move a meeting nobody edited.

The trap worth naming early: candidates hear “overlapping intervals” and reach for an interval tree inside three minutes. You almost never need one. Keep one owner’s meetings in a TreeMap keyed by start instant, and “does this new meeting clash with anything” is answered by two probes – floorEntry and ceilingKey – in O(log n) total, with no custom structure to write, debug or explain. An interval tree earns its keep only when intervals heavily overlap each other, and a sane person’s calendar does not. The rest of this page builds the scheduler around three mechanisms: the half-open overlap rule and the two probes that use it, the merge-and-sweep that produces a slot for a group, and a recurrence rule that is stored as a rule and expanded only inside the window being queried.

💡 Half-open interval = a range that includes its start instant and excludes its end instant, written [start, end). It is the reason a 10:00-11:00 meeting and an 11:00-12:00 meeting do not clash, and getting it wrong is the most common correctness bug in this problem.

💡 A machine-coding round = a timed sitting, commonly around 90 minutes, where you build a small working program and are graded on class design and correctness far more than on algorithmic cleverness. Learn more →

💡 TreeMap = a map that keeps its keys sorted and exposes navigation methods such as floorEntry and ceilingKey, each O(log n). The sorted order is incidental here; the navigation API is the reason to pick it. Learn more →

💡 Sweep (or sweep line) = walk a set of intervals in start order while carrying one running piece of state, so you answer a question in a single pass instead of comparing every pair. Here the state is “the busy block I am currently extending”.


Functional Requirements

  1. Book a meeting for a set of attendees over a half-open time range, optionally with a room.
  2. Conflict detection rejects a booking that overlaps an existing meeting for any required attendee or for the room, and must treat back-to-back meetings as legal.
  3. Free-slot search returns the earliest window of a given length after now in which every required attendee is free, respecting each attendee’s working hours in their own time zone.
  4. Optional attendees are advisory: a slot is still proposed when an optional person is busy, and the organiser is told who it does not suit.
  5. Recurring meetings are stored as a rule, not as rows, and support cancelling or moving a single occurrence without disturbing the series.
  6. Room allocation picks a free room by a swappable policy – smallest room that fits, nearest floor, or best equipment match.
  7. Reschedule and cancel update every affected calendar and notify the attendees of the change.

Non-Functional Requirements

  1. Conflict check in O(log n) per calendar, where n is that owner’s meeting count. No full scan on the booking path.
  2. Thread-safe booking – two organisers racing for the same room at the same instant produce exactly one meeting, and the loser gets a clear rejection rather than a corrupted calendar.
  3. Deterministic time – the system never calls Instant.now() or ZoneId.systemDefault() directly. A Clock and an explicit zone are injected, so tests are repeatable and a server in Oregon behaves like a server in Dublin.
  4. Bounded work per query – expanding a recurring series costs the query window, not the lifetime of the series.

💡 Injecting a Clock rather than calling Instant.now() inside the domain is the one change that makes time-dependent code testable: the demo on this page winds a fake clock by hand and nothing sleeps. Learn more →