πŸ“ Problem Details

input array intervals representing the start and end time for meetings return true or false based on whether a person could attend all meetings

πŸ’­What Were My Initial Thoughts?

- first need to sort all meetings in ascending order 
- we must attend the meeting for the entire duration
- there must not be any overlap between any meetings, if there are we can return false

πŸ’‘ Explanation of Solution

1. sort intervals by start time 
2. check for overlap between the end time of the previous interval and the start time of the current interval

βŒ› Complexity Analysis

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

πŸ’» Implementation of Solution

class Solution {
public:
    bool canAttendMeetings(vector<vector<int>>& intervals) {
        if (intervals.empty()) return true;
        
        // Sort meetings based on start time
        sort(intervals.begin(), intervals.end());
        
        // Check for overlapping meetings
        for (int i = 1; i < intervals.size(); i++) {
            if (intervals[i][0] < intervals[i - 1][1]) {
                return false; // Overlap detected
            }
        }
        
        return true; // No overlaps
    }
};