[LeetCode] Count Days Without Meetings

3169. Count Days Without Meetings

You are given a positive integer days representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array meetings of size n where, meetings[i] = [start_i, end_i] represents the starting and ending days of meeting i (inclusive).

Return the count of days when the employee is available for work but no meetings are scheduled.

Note: The meetings may overlap.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Solution {
public:
int countDays(int days, vector<vector<int>>& A) {
sort(rbegin(A), rend(A));
while(A.size()) {
int s = A.back()[0], e = A.back()[1];
while(A.size() and A.back()[0] <= e + 1) {
e = max(e, A.back()[1]);
A.pop_back();
}
days -= (e - s + 1);
}
return days;
}
};

Author: Song Hayoung
Link: https://songhayoung.github.io/2024/06/02/PS/LeetCode/count-days-without-meetings/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.