Problem Description
Given an array of meeting time intervals where each interval is represented as [start, end], determine if a person could attend all meetings without any overlapping intervals.
Key Insights
- Sort the intervals based on their starting times.
- Compare each interval's end time with the next interval's start time.
- Detect overlap if the end time of one meeting exceeds the start time of the following meeting.
- If no overlaps are detected, all meetings can be attended.
Space and Time Complexity
Time Complexity: O(n log n) due to sorting the intervals.
Space Complexity: O(1) if sorting is done in-place; otherwise O(n).
Solution
The solution starts by sorting the intervals in ascending order by their start times. After sorting, iterate through the intervals and for each consecutive pair, check if the previous meeting's end time exceeds the next meeting's start time. An overlap indicates that the person cannot attend all meetings. The primary data structure used is an array (or list) for holding the intervals. Sorting makes it easier to compare adjacent intervals for potential overlaps.