My Calendar I
MediumIntervals
Decode it first. Clues, constraints, pattern and plan before any code.Build a MyCalendar class for booking events. book(start, end) tries to add the event [start, end), which is half-open: it includes start but not end. If the new event would overlap any event already booked, reject it and return false without storing it. Otherwise store it and return true.
cal = MyCalendar()
cal.book(10, 20) → true
cal.book(15, 25) → false (15 to 20 is taken)
cal.book(20, 30) → true (starts exactly when the first ends)The TypeScript class has the same shape: new MyCalendar() and cal.book(start, end).
Constraints
0 <= start < end <= 10^9- At most
1000calls tobook.