Here is the simple solution:
class MyCalendar
bookings := []
function book(start, end)
for each (s, e) in bookings
if start < e and s < end then
return false
bookings.add((start, end))
return true
Two intervals and overlap if and only if and . This is the standard overlap check.
Time: per booking. Space: total.