Categories:

Tags:



Problem

Given an array of meeting time intervals where intervals[i] = [starti, endi], determine if a person could attend all meetings.

Constraints

  • 0 <= intervals.length <= 104
  • intervals[i].length == 2
  • 0 <= starti < endi <= 106

Solution

The problem Meeting Rooms can be solved by sorting intervals by their start date and then checking if any end dates overlap with future start dates.

Implementation

class Solution
{
  public:
    bool canAttendMeetings(vector<vector<int>> &intervals)
    {
        sort(intervals.begin(), intervals.end());
        for (int i = 0; i < (int)intervals.size() - 1; i++)
            if (intervals[i][1] > intervals[i + 1][0])
                return false;

        return true;
    }
};