Count the days with no scheduled meetings when meeting ranges include both endpoints and may overlap. Handle a large calendar and return the number of free days.
### Problem
An employee is available on every day from day `1` through day `days`. Each row `meetings[i] = [start_i, end_i]` schedules a meeting on every day in that inclusive range. Meetings may overlap.
Return the number of available days on which no meeting is scheduled.
```cpp
class Solution {
public:
int countDays(int days, vector<vector<int>>& meetings);
};
```
### Examples
**Example 1:**
```text
Input: days = 12, meetings = [[8,10],[2,5],[4,7]]
Output: 3
Explanation: Days 2 through 10 have meetings. The free days are 1, 11, and 12.
```
**Example 2:**
```text
Input: days = 8, meetings = [[1,8],[3,3],[1,2]]
Output: 0
Explanation: The meeting from day 1 through day 8 covers every available day.
```
### Constraints
- `1 <= days <= 10^9`.
- `1 <= meetings.length <= 10^5`.
- Each `meetings[i]` contains exactly two integers.
- `1 <= meetings[i][0] <= meetings[i][1] <= days`.
### Clarifying Questions
- Are both meeting endpoints occupied? Yes, both are included.
- Are meetings sorted or disjoint? Neither property is guaranteed.
- Does an overlapping day count more than once? No. A day either has a meeting or is free.
- Can free days occur before the first meeting or after the last one? Yes.
### What a Strong Answer Covers
- Counts every free day exactly once, including days at either end of the calendar.
- Handles overlapping, contained, and adjacent meeting ranges correctly.
- Supports the full day bound without allocating one entry per calendar day.
```hint Compare covered ranges
Consider the union of the inclusive meeting ranges. Account separately for any free days outside the first and last covered ranges.
```
Overview: Count the days with no scheduled meetings when meeting ranges include both endpoints and may overlap. Handle a large calendar and return the number of free days.
An employee is available on every day from day 1 through day days. Each row meetings[i] = [start_i, end_i] schedules a meeting on every day in that inclusive range. Meetings may overlap.
Return the number of available days on which no meeting is scheduled.
class Solution {
public:
int countDays(int days, vector<vector<int>>& meetings);
};
Examples
Example 1:
Input: days = 12, meetings = [[8,10],[2,5],[4,7]]
Output: 3
Explanation: Days 2 through 10 have meetings. The free days are 1, 11, and 12.
Example 2:
Input: days = 8, meetings = [[1,8],[3,3],[1,2]]
Output: 0
Explanation: The meeting from day 1 through day 8 covers every available day.
Constraints
1 <= days <= 10^9
.
1 <= meetings.length <= 10^5
.
Each
meetings[i]
contains exactly two integers.
1 <= meetings[i][0] <= meetings[i][1] <= days
.
Clarifying Questions Guidance
Are both meeting endpoints occupied? Yes, both are included.
Are meetings sorted or disjoint? Neither property is guaranteed.
Does an overlapping day count more than once? No. A day either has a meeting or is free.
Can free days occur before the first meeting or after the last one? Yes.
What a Strong Answer Covers Guidance
Counts every free day exactly once, including days at either end of the calendar.
Handles overlapping, contained, and adjacent meeting ranges correctly.
Supports the full day bound without allocating one entry per calendar day.