Greedy Algorithms8 sections · 316 units
Open in Course

Problem - My Calendar I

Online interval insertion

Implement a calendar that can book events. Each event has a start and end time. A new event can be booked if it does not overlap with any existing event.

For example, book [10,20][10,20] succeeds. Then book [15,25][15,25] fails (overlaps). Then book [20,30][20,30] succeeds (touching is okay). This is the online version of overlap detection. You cannot sort everything upfront because events arrive one at a time. You must check each new event against all existing ones.