[
sort
intervals
]
Leetcode 0252. Meeting Rooms
Problem statement
https://leetcode.com/problems/meeting-rooms/
Solution
All we need to to is to sort intervals by its starts and check that start of each interval is not less than end of previous.
Complexity
Time complexity is $O(n\log n)$, space complexity is $O(n)$.
Code
class Solution:
def canAttendMeetings(self, intervals):
intervals = sorted(intervals, key = lambda x:x[0])
return all(x[1]<=y[0] for x,y in zip(intervals, intervals[1:]))