Problem
Build a MyCalendar class for booking events. book(start, end) tries to add the event [start, end), which is half-open: it includes start but not end. If the new event would overlap any event already booked, reject it and return false without storing it. Otherwise store it and return true.
Example 1
cal = MyCalendar()
Example 2
- Input
- cal.book(10, 20)
- Output
- true
Example 3
- Input
- cal.book(15, 25)
- Output
- false
- Why
- 15 to 20 is taken
Example 4
- Input
- cal.book(20, 30)
- Output
- true
- Why
- starts exactly when the first ends
The TypeScript class has the same shape: new MyCalendar() and cal.book(start, end).
Constraints
0 <= start < end <= 10^9At most 1000 calls to book.