This question evaluates interval conflict detection and efficient range storage skills, assessing algorithm design and data structure competency within the Coding & Algorithms domain.
Design a calendar booking system that stores half-open time intervals [start, end) (inclusive of start, exclusive of end).
Implement a class with a method:
book(start, end) -> boolean
The method should:
true
and add the event if it does
not
overlap with any existing event.
false
and do
not
add the event if it overlaps with an existing event.
Two events [s1, e1) and [s2, e2) overlap iff max(s1, s2) < min(e1, e2).
Operations:
book(10, 20)
→
true
book(15, 25)
→
false
(overlaps with
[10,20)
)
book(20, 30)
→
true
(touching at 20 is allowed)
10^3
to
10^5
bookings
0 <= start < end <= 10^9