My Calendar Booking
Medium · binary search
A meeting room can only host one event at a time. You are given a list bookings, where each bookings[i] = [start, end] is a request to reserve the room from minute start up to, but not including, minute end.
Requests are handled in the order given. A request is accepted if its time range shares no minute with any request accepted before it; otherwise it is rejected, and the room stays as it was. A booking that ends at minute 10 and another that starts at minute 10 do not clash.
Return a list of booleans, one per request in order: true if that request was accepted and false if it was rejected.
Examples
Example 1
Input: bookings = [[10, 20], [15, 25], [20, 30]]
Output: [true, false, true]
The second request overlaps minutes 15 to 19 of the first, so it is rejected. The third starts exactly when the first ends, so it fits.
Example 2
Input: bookings = [[5, 10], [1, 5], [10, 12], [3, 7]]
Output: [true, true, true, false]
The first three only touch at their edges. The last one overlaps both the first and the second.
Constraints
- 1 <= len(bookings) <= 2000
- bookings[i].length == 2
- 0 <= start < end <= 10^9