DesignTheSystem/dev
MEDIUM Low-Level Design (LLD) 12 automated tests

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.

DifficultyMEDIUM
Design focusInterval logic: overlaps, merging and gaps
Automated grading3 public + 9 hidden tests (12 total)
Phase 2 follow-upWeekly meetings
LanguageTypeScript (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 (core)

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 (edge)

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 (core)

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

More low-level design problems