# LC 3169. Count Days Without Meetings
### [Problem link](https://leetcode.com/problems/count-days-without-meetings/)
###### tags: `leedcode` `medium` `c++`
You are given a positive integer <code>days</code> representing the total number of days an employee is available for work (starting from day 1). You are also given a 2D array <code>meetings</code> of size <code>n</code> where, <code>meetings[i] = [start_i, end_i]</code> represents the starting and ending days of meeting <code>i</code> (inclusive).
Return the count of days when the employee is available for work but no meetings are scheduled.
**Note:** The meetings may overlap.
**Example 1:**
Input: days = 10, meetings = [[5,7],[1,3],[9,10]]
Output: 2
Explanation:
There is no meeting scheduled on the 4<sup>th </sup> and 8<sup>th </sup> days.
**Example 2:**
Input: days = 5, meetings = [[2,4],[1,3]]
Output: 1
Explanation:
There is no meeting scheduled on the 5<sup>th </sup>day.
**Example 3:**
Input: days = 6, meetings = [[1,6]]
Output: 0
Explanation:
Meetings are scheduled for all working days.
**Constraints:**
- 1 <= days <= 10<sup>9</sup>
- 1 <= meetings.length <= 10<sup>5</sup>
- meetings[i].length == 2
- 1 <= meetings[i][0] <= meetings[i][1] <= days
## Solution 1
#### C++
```cpp=
class Solution {
public:
int countDays(int days, vector<vector<int>>& meetings) {
sort(meetings.begin(), meetings.end());
int meetingDay = 0;
int left = meetings[0][0];
int right = meetings[0][1];
for (int i = 1; i < meetings.size(); i++) {
if (meetings[i][0] <= right) {
right = max(right, meetings[i][1]);
} else {
meetingDay += right - left + 1;
left = meetings[i][0];
right = meetings[i][1];
}
}
meetingDay += right - left + 1;
return days - meetingDay;
}
};
```
>### Complexity
>n = meetings.length
>| | Time Complexity | Space Complexity |
>| ----------- | --------------- | ---------------- |
>| Solution 1 | O(nlogn) | O(1) |
## Note
跟[LC 56. Merge Intervals](https://hackmd.io/@Alone0506/SJyRonX43)類似
合併區間的時候計算meetingDay有幾天, 最後結果為days - meetingDay;