Create a class called EventScheduler that allows you to manage event bookings. You can always add a new event without restrictions.
The class will include one method, reserve(int begin, int finish). This represents booking an event in the half-open interval [begin, finish), which means all points x where begin <= x < finish.
A J-booking means that there are J events overlapping at some point in time (i.e., there exists a time that is common to all J events).
Each time you call EventScheduler.reserve, return the largest number J such that a J-booking exists in the calendar.
EventScheduler(); EventScheduler.reserve(12, 22); // returns 1 EventScheduler.reserve(55, 65); // returns 1 EventScheduler.reserve(12, 42); // returns 2 EventScheduler.reserve(7, 17); // returns 3 EventScheduler.reserve(7, 12); // returns 3 EventScheduler.reserve(27, 57); // returns 3 # Explanation: # The first two events are booked and don't overlap, so the max J-booking is 1. # The third event [12, 42) overlaps with the first event, increasing max J-booking to 2. # The next events increase the max J-booking to 3. # Although the last event itself overlaps only with 2 events, the overall max remains 3 due to previous overlaps.
EventScheduler.reserve will not exceed 450.begin and finish will be integers in the range [0, 10^9].