Meeting Rooms
Examples
Example 1:
Input: intervals = [(0,30),(5,10),(15,20)]
Output: false
Explanation:
Example 2:
Input: intervals = [(5,8),(9,15)]
Output: true
Example 1:
Input: intervals = [(0,30),(5,10),(15,20)]
Output: false
Explanation:
Example 2:
Input: intervals = [(5,8),(9,15)]
Output: true
Given an array of meeting time interval objects consisting of start and end times [[start_1,end_1],[start_2,end_2],...] (start_i < end_i), determine if a person could add all meetings to their schedule without any conflicts.
Note: (0,8),(8,10) is not considered a conflict at 8
(0,30) and (5,10) will conflict(0,30) and (15,20) will conflict0 <= intervals.length <= 5000 <= intervals[i].start < intervals[i].end <= 1,000,000Sort meetings by start time, then check consecutive intervals for overlap. If any meeting starts before the previous one ends, a conflict exists.
After sorting, any conflict must occur between adjacent meetings. If no adjacent overlap exists, then no meetings overlap at all.
O(n log n)O(1)class Solution:
def canAttendMeetings(self, intervals: List[List[int]]) -> bool:
intervals.sort(key=lambda x: x[0])
for i in range(1, len(intervals)):
if intervals[i][0] < intervals[i - 1][1]:
return False
return True