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) {
(meetings.begin(), meetings.end());
sort.push_back({days+1, days+1});
meetingsint ans = 0;
int prev = 0;
for (int i = 0; i < meetings.size(); ++i) {
if (meetings[i][0] - prev - 1 > 0) {
+= meetings[i][0] - prev - 1;
ans }
= max(prev, meetings[i][1]);
prev }
return ans;
}
};