Back to solutions
Meeting Rooms
EasyGreedyGiven meeting time intervals, return true if a person could attend all meetings without overlaps.
Constraints
- 0 <= intervals.length <= 10^4
- intervals[i] = [start, end]
Sort and check adjacent
Time O(n log n)Space O(1)
Sort meetings by start time. If any meeting starts before the previous one ends, there is a conflict; otherwise all meetings can be attended.
#include <bits/stdc++.h>
using namespace std;
bool canAttendMeetings(vector<vector<int>>& intervals) {
sort(intervals.begin(), intervals.end());
for (int i = 1; i < (int)intervals.size(); i++)
if (intervals[i][0] < intervals[i - 1][1]) return false;
return true;
}