Skip to content
Onsite

My Calendar I

MediumP3Coding

Implement a calendar that accepts a booking only if it does not overlap an existing one.

  • MyCalendar() creates an empty calendar.
  • book(start, end) tries to add the half-open event [start, end), which includes start but not end. If it overlaps no earlier accepted event, store it and return true; otherwise do not store it and return false.

Two events overlap when some moment lies in both. Events [10,20) and [20,30) do not overlap.

Example 1

Input
["MyCalendar","book","book","book"] [[],[10,20],[15,25],[20,30]]
Output
[null,true,false,true]
Why
[15,25) overlaps [10,20); [20,30) only touches it.

Constraints

  • 0 <= start < end <= 10^9
  • At most 1000 calls to book

Hints

Run checks the 2 visible tests, Submit all 5.