Design a calendar that stores non-overlapping time bookings and rejects any request that would overlap an existing event.
Problem
Design a calendar system that supports adding events defined by a start and end time.
An event is represented by a half-open interval [start, end), meaning the event includes start but excludes end.
Implement a booking operation that:
- accepts the event if it does not overlap any existing event already booked
- rejects it otherwise
Two events overlap if they share any time point.
Your task is to maintain the calendar across many booking requests and return whether each new request can be added successfully.
Notes
- Time values are integers.
- Events are half-open intervals, so an event ending at time
tdoes not conflict with another event starting at timet. - You only need to support insertion and conflict checking; no deletion is required.
Input Format
The input consists of a sequence of booking requests, each containing two integers:
startend
Each request asks whether the interval [start, end) can be added to the calendar.
Output Format
For each booking request, output:
trueif the event can be inserted without overlapping any existing eventfalseotherwise
Constraints
0 <= start < end- Times are integers
- Multiple booking requests may be processed
- The calendar must never contain overlapping intervals
Example 1
Input
book(10, 20) book(15, 25) book(20, 30)
Output
true false true
Explanation
[10, 20)is added successfully.[15, 25)overlaps[10, 20), so it is rejected.[20, 30)starts exactly when the first event ends, so it does not overlap and is accepted.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.