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:

[5,15] would cause triple booking with [10,20] and [10,40].

Input:input = [[10,20],[50,60],[10,40],[5,15]]
Output:false
Explanation:

For input = [[10,20],[50,60],[10,40],[5,15]], the answer is false because the my calendar ii condition is not met.

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⁹

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!