Imagine you're a busy professional trying to organize your calendar for the day. You have a list of meeting time intervals and need to determine if you can attend all meetings without any conflicts.
Given an array intervals where intervals[i] = [starti, endi] represents the start and end times of meeting i, return true if you can attend all meetings, or false if there are any overlapping meetings.
Goal: Check if any two meetings overlap in time.
Input: Array of meeting intervals (each interval has start and end time)
Output: Boolean value indicating if all meetings can be attended
Two meetings overlap if one starts before the other ends. For example, meetings [1,3] and [2,4] overlap because meeting 2 starts at time 2, which is before meeting 1 ends at time 3.
Input & Output
Visualization
Time & Space Complexity
O(n log n) for sorting + O(n) for checking consecutive meetings = O(n log n) overall
If we can sort in-place, otherwise O(n) for creating a sorted copy
Constraints
- 0 โค intervals.length โค 104
- intervals[i].length == 2
- 0 โค starti < endi โค 106
- Each interval represents a valid meeting time