729. My Calendar I
Practice My Calendar I for free on NudgeCode: Medium, Binary Search pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
Design a calendar that accepts an event only if it does not double book, i.e. overlap an event already in the calendar. An event is the half-open interval [startTime, endTime), so [10, 20) and [20, 30) do not overlap.
book(startTime, endTime)adds the event and returnstrueif it doesn't overlap any booked event; otherwise it returnsfalseand the calendar is unchanged.
Each test is a list of operations and their arguments; the expected output lists what each call returns (null for the constructor).
Example
["MyCalendar","book","book","book"]
[[],[10,20],[15,25],[20,30]]
-> [null,true,false,true]
Constraints
- 0 <= startTime < endTime <= 10^9
- Up to 1000 calls to
book