Meeting Rooms

Given meeting time intervals, decide whether one person could attend every meeting.

A way to picture it

Sort your meetings by start time and walk through your day. The only way to be double-booked is if a meeting starts before the one right before it has ended.

How to approach it

Sort by start and compare each meeting only with its neighbour. Any overlap shows up between neighbours.

Example

Input: {"intervals":[[0,30],[5,10],[15,20]]}. Output: false.

Complexity: O(n log n) time and O(1) extra space. Sorting dominates the single scan.

This page includes an animated walkthrough, Java and Python solutions, and a question to check your understanding.