You are implementing a program to use as your calendar. We can add a new event if adding the event will not cause a double booking. A double booking happens when two events have some non-empty intersection (i.e., some moment is common to both events). Implement the MyCalendar class: - MyCalendar() Initializes the calendar object. - boolean book(int start, int end) Returns true if the event can be added without a double booking. Otherwise, return false and do not add the event.
Example 1
Input: operations = ["MyCalendar","book","book","book"], args = [[],[10,20],[15,25],[20,30]]
Output: [null,true,false,true]
Explanation: [10,20) is booked. [15,25) overlaps it during 15-20, so it is rejected. [20,30) starts exactly when [10,20) ends, so there is no overlap and it is accepted.
Example 2
Input: operations = ["MyCalendar","book","book","book"], args = [[],[1,2],[2,3],[3,4]]
Output: [null,true,true,true]
Explanation: Each event starts exactly when the previous one ends, so none of them overlap and all three are booked.
Example 3
Input: operations = ["MyCalendar","book","book"], args = [[],[1,10],[1,10]]
Output: [null,true,false]
Explanation: The second [1,10) covers exactly the same time as the first, so it would be a double booking and is rejected.
Maintain a sorted list of booked intervals. For each new booking, binary search to find where it would be inserted and check if it overlaps with neighbors.
Run checks all cases above. Submit evaluates all test cases.