Meeting rooms

July 21, 2022

intervals

Problem URL: Meeting rooms

We will sort the given array based on start time. Then we can compare, if the end of first meeting is before the start of last meeting, if yes return False, else return True.

class Solution:
    def canAttendMeetings(self, intervals: : List[List[int]]) -> bool:
        intervals.sort(key=lambda i: i[0])

        for i in range(1, len(intervals)):
            i1 = intervals[i-1]
            i2 = intervals[i]

            if i1[1] > i2[0]:
                return False
        return True

Time Complexity: O(nlog(n))
Space Complexity: O(1)