Design Calendar Scheduling (Low-Level Design)
Book meetings without double-booking anyone, and find free time for a group. Focus: Interval logic: overlaps, merging and gaps.
| Difficulty | MEDIUM |
|---|---|
| Design focus | Interval logic: overlaps, merging and gaps |
| Automated grading | 3 public + 9 hidden tests (12 total) |
| Phase 2 follow-up | Weekly meetings |
| Language | TypeScript (OOP / Machine Coding) |
Problem statement
Time is in minutes. An event covers [start, end): it includes start but not end, so one meeting can end exactly when the next starts.
Nobody can be in two events at once: adding an event that overlaps any attendee's existing event throws, and nothing is added.
Functional requirements
- addEvent(id, title, start, end, attendees): end must be after start, ids are unique, at least one attendee.
- cancel(id) removes an event (an unknown id throws).
- eventsFor(person, from, to) lists ids of that person's events overlapping [from, to), ordered by start, then id.
- freeSlots(people, from, to, minLength) returns [start, end] gaps in [from, to) when none of them is busy, at least minLength long, in order.
Required API & starter interface
Implement the TypeScript class interface below. You can add any helper classes, policies or strategies you need:
class Calendar {
addEvent(id: string, title: string, start: number, end: number, attendees: string[]): void {
throw new Error("Not implemented");
}
cancel(id: string): void {
throw new Error("Not implemented");
}
eventsFor(person: string, from: number, to: number): string[] {
throw new Error("Not implemented");
}
freeSlots(people: string[], from: number, to: number, minLength: number): [number, number][] {
throw new Error("Not implemented");
}
}
Public test cases
Your code runs against 3 public tests plus 9 hidden edge-case tests in a sandbox:
Back-to-back meetings are fine
var c = new Calendar();
c.addEvent("e1", "Standup", 540, 555, ["ann"]);
c.addEvent("e2", "Review", 555, 600, ["ann"]);
assertEqual(c.eventsFor("ann", 0, 1440), ["e1", "e2"]);
Overlaps are refused
var c = new Calendar();
c.addEvent("e1", "A", 600, 660, ["ann"]);
assertThrows(function () { c.addEvent("e2", "B", 630, 700, ["bob", "ann"]); });
assertEqual(c.eventsFor("bob", 0, 1440), []);
Free time for two people
var c = new Calendar();
c.addEvent("a", "A", 600, 660, ["ann"]);
c.addEvent("b", "B", 700, 720, ["bob"]);
assertEqual(c.freeSlots(["ann", "bob"], 540, 780, 30), [[540, 600], [660, 700], [720, 780]]);
Design & structure checks
Beyond passing tests, the grader inspects your class structure for clean object-oriented design:
- Overlap checking is written once: Adding, listing and free-time search all ask whether two intervals overlap. One helper means one place to get the half-open rule right.
Phase 2: Change request
In real interviews, the follow-up tests whether your design is extensible. After your first version passes all 12 tests, you unlock the change request: Weekly meetings.
Pair with High-Level System Design
Ready to scale Calendar Scheduling across distributed servers? Try the matching HLD simulator problem: Design Calendar System.
Relevant low-level design lessons
Time you can control
Handle expiry and windows without timers, so behaviour is testable.
Map plus ordered list: the LRU trick
Build constant-time get, put and evict-oldest.
Observer: tell others without knowing them
Let other parts react to events without the source depending on them.
More low-level design problems
Design Movie Ticket Booking
Hold seats for a few minutes, confirm or release them, and never sell one seat twice.
Design Job Scheduler
Run jobs when they are due, in a fixed order, with cancelling and (later) repeating jobs.
Design LRU Cache
A fixed-size cache that throws out the least recently used entry when full, with every operation in constant time.
Design Rate Limiter
Two rate-limiting algorithms behind one interface, so callers can swap them.