Description
Implement a calendar that can add events allowing at most 2 overlapping events at any time. Return false if adding an event causes triple booking.
Examples
Input:
["book",10,20],["book",50,60],["book",10,40],["book",5,15]Output:
[true,true,true,false]Explanation:
The first three bookings are accepted, and the fourth would cause a triple booking, so the result is [true,true,true,false].
Input:
input = [[10,20],[50,60],[10,40],[5,15]]Output:
[true,true,true,false]Explanation:
The booking sequence returns [true,true,true,false].
Input:
["book",1,5],["book",2,6],["book",3,7],["book",4,8],["book",9,12]Output:
[true,true,true,false,true]Explanation:
First three bookings create overlapping intervals: [1,5], [2,6], [3,7] with maximum 2 overlaps allowed. The fourth booking [4,8] would overlap with all three existing intervals in the range [4,5], creating a triple booking, so it's rejected. The fifth booking [9,12] doesn't overlap with any existing bookings, so it's accepted.
Constraints
- •
0 ≤ start < end ≤ 10⁹