3169: Count-Days-Without-Meetings
Medium

You start off the algorithm by sorting the meetings from smallest to largest.

Next, we keep track of the maximum meetings[i][1] value with prev, as that tells us when the previous meeting ends. Then, when we iterate through meetings, we check if meetings[i][0] > prev + 1:

Finally, we just simply sum up these values into ans and return it.

Code:

class Solution {
public:
    int countDays(int days, vector<vector<int>>& meetings) {
        sort(meetings.begin(), meetings.end());
        meetings.push_back({days+1, days+1});
        int ans = 0;
        int prev = 0;
        for (int i = 0; i < meetings.size(); ++i) {
            if (meetings[i][0] - prev - 1 > 0) {
                ans += meetings[i][0] - prev - 1;
            }
            prev = max(prev, meetings[i][1]);
        }
        
        return ans;
    }
};

Complexity: