My Calendar II

You are building a reservation system for a small studio that can handle at most two overlapping bookings at the same time. The studio has flexible partitions so two events can run in parallel, but a third simultaneous event would exceed capacity and must be rejected.

Design a class MyCalendarTwo that supports the following:

  • MyCalendarTwo() creates an empty calendar with no reservations.
  • book(start, end) tries to add a half open interval [start, end). If adding it would cause any point in time to be covered by three or more booked intervals, the call must not add the interval and must return false. Otherwise it adds the interval and returns true. A double overlap is allowed, a triple overlap is not.

An interval [a, b) covers a time t when a <= t < b. Two intervals that only touch at an endpoint do not overlap.

Examples
Input: [["MyCalendarTwo","book","book","book","book","book","book"],[[],[10,20],[50,60],[10,40],[5,15],[5,10],[25,55]]]
Output: [null,true,true,true,false,true,true]
Hints

My Calendar II

You are building a reservation system for a small studio that can handle at most two overlapping bookings at the same time. The studio has flexible partitions so two events can run in parallel, but a third simultaneous event would exceed capacity and must be rejected.