diff --git a/3169. Count Days Without Meetings b/3169. Count Days Without Meetings new file mode 100644 index 0000000..9a55912 --- /dev/null +++ b/3169. Count Days Without Meetings @@ -0,0 +1,39 @@ +class Solution { +public: + int countDays(int days, vector>& meetings) { + const int n = meetings.size(), N=2*n; + vector info(N); + int i=0; + + // Encode meeting start and end + for (auto& m : meetings) { + const unsigned s= m[0], e=m[1]; + info[i++]=(s<<1)|1; // Start, mark with LSB=1 + info[i++]=(e+1)<<1; // End (exclusive) + } + + // Sort the events + sort(info.begin(), info.end()); + + int overlap=0, cnt=0, last=1; + + // Process events in sorted order + for (int i=0; i>1; // Extract day + const bool isStart=info[i]&1; + + // If no overlap, count the days between last and current + if (overlap==0 && last