23 · Binary Search Trees

#729 My Calendar I

Mediumsolve on LeetCode ↗

frequently reported atUberIntuitByteDance / TikTokGoogleAmazonOracle

the problem

In plain words

Implement MyCalendar.book(startTime, endTime) for half-open intervals [start, end). Add the event and return true unless it overlaps an existing one, in which case return false.

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

out true, false, true

[20,30) only touches [10,20) — touching is fine.

  • 0 ≤ start < end ≤ 10⁹
  • At most 1000 calls to book

your turn

Try it before you peek

Read the examples, say the brute force out loud, then write code: here or on LeetCode ↗. Stuck for 20 minutes? Open one hint at a time.

Solve it in the browser

Design: implement every operation. Compiled by the real javac (Java 17) and judged right here — nothing is sent anywhere.

    Solutions are hidden so you can try first. Even 20 minutes of real effort makes the answer stick far better than reading it.

    Marking the problem solved, or opening every hint, also shows it.

    practise next

    Similar problems

    1. #56
      Merge Intervals
      Mediumin Intervals
    2. #253
      Meeting Rooms II
      Mediumin IntervalsLeetCode Premium
    3. #220