You are implementing a program to use as your calendar. We can add a new event if adding the event will not cause a **triple booking**. A **triple booking** happens when three events have some non-empty intersection (i.e., some moment is common to all the three events.) The event can be represented as a pair of integers `start` and `end` that represents a booking on the half-open interval `[start, end)`, the range of real numbers `x` such that `start <= x < end`. Implement the `MyCalendarTwo` class: - `MyCalendarTwo()` Initializes the calendar object. - `boolean book(int start, int end)` Returns `true` if the event can be added to the calendar successfully without causing a **triple booking**. Otherwise, return `false` and do not add the event to the calendar.
Example 1
Input: operations = ["MyCalendarTwo","book","book","book","book","book","book"], args = [[],[10,20],[50,60],[10,40],[5,15],[5,10],[25,55]]
Output: [null,true,true,true,false,true,true]
Explanation: After [10,20), [50,60) and [10,40), the time 10-20 is booked twice. [5,15) would add a third booking during 10-15, so it is rejected. [5,10) ends right as the double-booked part starts, so it is fine. [25,55) overlaps [10,40) and [50,60) at different times, so nothing is booked three times.
Example 2
Input: operations = ["MyCalendarTwo","book","book"], args = [[],[1,2],[2,3]]
Output: [null,true,true]
Explanation: [1,2) and [2,3) are half-open, so they only touch at 2 and never overlap. Both are accepted.
Example 3
Input: operations = ["MyCalendarTwo","book","book","book"], args = [[],[0,10],[0,10],[0,10]]
Output: [null,true,true,false]
Explanation: Two copies of [0,10) create a double booking. A third copy would make it triple, so it is rejected.
Keep two lists: all booked intervals, and the intervals that are already double-booked (overlaps). A new event is rejected only if it overlaps any double-booked interval (that would make a triple). Otherwise add it, and record its overlaps with existing bookings as new double-booked intervals.
Run checks all cases above. Submit evaluates all test cases.