From 2416e18b86b066ca6f59a5dffa6ab42fcd48b734 Mon Sep 17 00:00:00 2001 From: chayan das Date: Fri, 11 Jul 2025 13:45:13 +0530 Subject: [PATCH] Create 2402. Meeting Rooms III 1 --- 2402. Meeting Rooms III 1 | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 2402. Meeting Rooms III 1 diff --git a/2402. Meeting Rooms III 1 b/2402. Meeting Rooms III 1 new file mode 100644 index 0000000..e7d92ad --- /dev/null +++ b/2402. Meeting Rooms III 1 @@ -0,0 +1,37 @@ +class Solution { + public: + int mostBooked(int n, vector>& meetings) { + vector booked(n, 0); + priority_queue, greater<>> idle; + priority_queue, vector>, greater<>> busy; + for (int i = 0; i < n; ++i) { idle.push(i); } + ranges::sort(meetings, [](const auto& lhs, const auto& rhs) { return lhs[0] < rhs[0]; }); + for (const auto& m : meetings) { + int start = m[0], end = m[1]; + while (!busy.empty() && busy.top().first <= start) { + idle.push(busy.top().second); + busy.pop(); + } + if (!idle.empty()) { + int room = idle.top(); + idle.pop(); + busy.push({end, room}); + ++booked[room]; + } else { + auto p = busy.top(); + busy.pop(); + p.first += end - start; + busy.push(p); + ++booked[p.second]; + } + } + int res = -1, cur = -1; + for (int i = 0; i < n; ++i) { + if (booked[i] > cur) { + cur = booked[i]; + res = i; + } + } + return res; + } +};