Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

My Calendar III

Hard

Topics
ArraySweep LineSegment TreeOrdered Map

You are given a list of bookings where bookings[i] = [start, end] represents a half-open interval [start, end).

Book them one at a time, in order. A k-booking happens when k events have a non-empty intersection. After each booking, record the largest k such that a k-booking exists.

Return the array of those values.

The original problem is a class with a book method called repeatedly. This judge passes the whole call sequence at once and asks for the answer after each call — the same state machine, batched.

Example 1

Input:  bookings = [[10,20],[50,60],[10,40],[5,15],[5,10],[25,55]]
Output: [1,1,2,3,3,3]

Example 2

Input:  bookings = [[1,2],[1,2],[1,2]]
Output: [1,2,3]

Constraints

  • 1 <= bookings.length <= 400
  • 0 <= start < end <= 10^9
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access