> [!META]- Inline Metadata > [tags:: #career #concepts/programming/intervals ] > [project group:: Neetcode 150] > [difficulty:: easy] > [status:: done] > [link:: ] > [up:: [[Leetcode MOC]]] ## Problem Given an array of meeting time intervals consisting of start and end times `[[s1,e1],[s2,e2],...] (si < ei)`, determine if a person could attend all meetings. (0,8),(8,10) is not conflict at 8 **Example 1** ``` Input: intervals = [(0,30),(5,10),(15,20)] Output: false Explanation: (0,30), (5,10) and (0,30),(15,20) will conflict ``` **Example 2** ``` Input: intervals = [(5,8),(9,15)] Output: true Explanation: Two times will not conflict ``` ## Solution ### Mine #### Python ```python class Solution: """ @param intervals: an array of meeting time intervals @return: if a person could attend all meetings """ def can_attend_meetings(self, intervals: List[Interval]) -> bool: intervals.sort(key=lambda interval: interval.start) for idx, interval in enumerate(intervals[:-1]): if interval.end < intervals[idx + 1].start: return False return True ``` #### Rust ### LC's ## Things I Learned ## Scratchpad Brute force way: 1. Sort list of intervals by start time 2. for each interval, ensure no numbers from following intervals are within that interval 1. Since the list is now sorted, we only need to check if any later start time is within the interval in question, the end time will only be within the interval if the start time also is. We actually only need to check adjacent intervals after sorting, since if the next interval is entirely outside the current one (i2.start > i1.end), the following intervals will also be. Because of sort, time complexity is $O(n log n)$