Skip to main content
Back to problems
Leetcode
Medium
Ordered Structures
Intervals
My Calendar I

Design a calendar that stores non-overlapping time bookings and rejects any request that would overlap an existing event.

Acceptance 0%
Problem Statement

Problem

Design a calendar system that supports adding events defined by a start and end time.

An event is represented by a half-open interval [start, end), meaning the event includes start but excludes end.

Implement a booking operation that:

  • accepts the event if it does not overlap any existing event already booked
  • rejects it otherwise

Two events overlap if they share any time point.

Your task is to maintain the calendar across many booking requests and return whether each new request can be added successfully.

Notes

  • Time values are integers.
  • Events are half-open intervals, so an event ending at time t does not conflict with another event starting at time t.
  • You only need to support insertion and conflict checking; no deletion is required.

Input Format

The input consists of a sequence of booking requests, each containing two integers:

  • start
  • end

Each request asks whether the interval [start, end) can be added to the calendar.

Output Format

For each booking request, output:

  • true if the event can be inserted without overlapping any existing event
  • false otherwise

Constraints

  • 0 <= start < end
  • Times are integers
  • Multiple booking requests may be processed
  • The calendar must never contain overlapping intervals
Examples
Sample cases returned by the problem API.

Example 1

Input

book(10, 20)
book(15, 25)
book(20, 30)

Output

true
false
true

Explanation

  • [10, 20) is added successfully.
  • [15, 25) overlaps [10, 20), so it is rejected.
  • [20, 30) starts exactly when the first event ends, so it does not overlap and is accepted.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.