Practice My Calendar III
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
MyCalendarThree.book(startTime,endTime) always adds the half-open event [startTime,endTime) and returns the greatest number of simultaneous events anywhere in the calendar so far. Events sharing only an endpoint do not overlap. Practice approach: Add +1 at each start and -1 at each end in an ordered map. Sweep the combined deltas to find the maximum prefix sum. Recomputing after each insertion is adequate for 400 bookings; a dynamic segment tree supports larger streams. Unlike Calendar I and II, this class never rejects a booking.
Source: My Calendar III on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
["MyCalendarThree","book","book","book"] [[],[4,8],[6,10],[7,9]]
[null,1,2,3]
All three bookings are accepted. The interval [7,8) belongs to all three, so the final maximum overlap is three.
Constraints
Related LeetCode Problems
Practice more problems similar to My Calendar III.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.