968. My Calendar III (Maximum K-Booking)

HardTreesSegment TreeSweep LineOrdered Map

Process a sequence of bookings, each a half-open interval [start, end). After each booking is added, return the maximum number of bookings that overlap at any single point in time (the maximum k-booking). Return the sequence of these maxima as an array, one per booking in order. The input is a JSON array of [start, end] bookings.

Input: A JSON array of [start, end] bookings.

Output: Array — the max k-booking after each booking.

Examples

Example 1
Input: [[10,20],[50,60],[10,40],[5,15],[5,10],[25,55]]
Output: [1,1,2,3,3,3]
Explanation: Overlap peaks grow to 3.
Example 2
Input: [[1,2]]
Output: [1]
Explanation: A single booking.
Example 3
Input: [[1,10],[1,10],[1,10]]
Output: [1,2,3]
Explanation: Three overlapping bookings.

Constraints

Asked by

Google
Solve this problem in the editor →