My Calendar II

Medium Intervals

Problem

Implement a calendar that allows a range to be booked twice, but rejects a booking that would be triple-booked. Intervals are half-open.

Original: LeetCode 731: My Calendar II.

Examples

Example 1

Input`MyCalendarTwo: book(10, 20), book(50, 60), book(10, 40), book(5, 15), book(5, 10), book(25, 55)`
Output`[true, true, true, false, true, true]`

book(5, 15) would triple-book [10, 15).

Constraints

  • 0 <= start < end <= 10^9
  • At most 1000 calls will be made to book.

Hints

Solution

Tried it yourself? The approach, complexity, and code stay hidden until you choose.

Sources (1)
  1. LeetCode 731: My Calendar IIleetcode.com