Problem
Build a MyCalendarTwo class. book(start, end) tries to add the half-open event [start, end). Double bookings are fine, but a triple booking (some moment covered by three events) is not. If the new event would cause a triple booking, return false and do not store it. Otherwise store it and return true.
Example 1
cal = MyCalendarTwo()
Example 2
- Input
- cal.book(10, 20)
- Output
- true
Example 3
- Input
- cal.book(50, 60)
- Output
- true
Example 4
- Input
- cal.book(10, 40)
- Output
- true
- Why
- double booked during 10 to 20
Example 5
- Input
- cal.book(5, 15)
- Output
- false
- Why
- 10 to 15 would be triple booked
Example 6
- Input
- cal.book(5, 10)
- Output
- true
Example 7
- Input
- cal.book(25, 55)
- Output
- true
The TypeScript class has the same shape: new MyCalendarTwo() and cal.book(start, end).
Constraints
0 <= start < end <= 10^9At most 1000 calls to book.