My Calendar I
Implement MyCalendar with a book(start, end) method for half-open events [start, end). Return True and record the event if it does not double-book (overlap) any existing event; otherwise return False and record nothing.
Open official problem prompt ↗Accept a stream of reservation requests, admitting each only if it does not clash with any previously admitted one.
A single meeting room with a receptionist. When a request arrives, the receptionist glances only at the booking that ends just before it and the one that starts just after it; if neither collides, the slot is granted.
- Input
- book(10, 20), book(15, 25), book(20, 30)
- Output
- [true, false, true]
- Why
- 10-20 is free; 15-25 overlaps 10-20 so it is rejected; 20-30 only touches 20 (half-open) so it fits.
0 <= start < end <= 10^9At most 1000 calls to book