You're building a smart scheduling system that tracks booking overlaps in real-time. Every time someone books a time slot [startTime, endTime), you need to determine the maximum number of events that overlap at any point in time.
A k-booking occurs when k events have some non-empty time intersection - meaning there's at least one moment when all k events are happening simultaneously.
Your task: Implement the MyCalendarThree class that can:
MyCalendarThree()- Initialize an empty calendarbook(startTime, endTime)- Add a new booking and return the maximum overlap count across all bookings
Note: Time intervals are half-open [start, end), so an event ending at time t doesn't conflict with an event starting at time t.
Input & Output
Visualization
Time & Space Complexity
Each booking operation takes O(log n) for TreeMap operations, across n bookings
Store at most 2n time points in the TreeMap
Constraints
-
0 โค
start<endโค 109 -
At most 400 calls will be made to
book -
Time intervals are half-open:
[start, end)