From b00c04b954cdd43f4255316eeaa2a88392f74acd Mon Sep 17 00:00:00 2001 From: chayan das <110921638+Chayandas07@users.noreply.github.com> Date: Mon, 24 Mar 2025 18:23:48 +0530 Subject: [PATCH] Create 3169. Count Days Without Meetings --- 3169. Count Days Without Meetings | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 3169. Count Days Without Meetings 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