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 includesstartbut notend. If it overlaps no earlier accepted event, store it and returntrue; otherwise do not store it and returnfalse.
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
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 2 visible tests, Submit all 5. ⌘Enter runs, ⌘⇧Enter submits.