Question

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.

This is anintervals question.

Idea

  • Sort by start time
  • Check if the start time of the current interval starts before the end time of the previous interval
    • If so, return False
  • Return True

Solution

"""
Definition of Interval:
class Interval(object):
    def __init__(self, start, end):
        self.start = start
        self.end = end
"""
 
class Solution:
    def canAttendMeetings(self, intervals: List[Interval]) -> bool:
        intervals.sort(key=lambda x: x.start)
        for i in range(1, len(intervals)):
            lastEnd = intervals[i-1].end
            if intervals[i].start < lastEnd:
                return False
        return True