Count Days Without Meetings | Leetcode 3169

preview_player
Показать описание
This video explains Count Days Without Meetings using the most optimal sorting merging and line sweep 1D approaches.
----------------------------------------------------------------------------------------------------------------------------------------------------------------
🟣 JOIN our 𝐋𝐈𝐕𝐄 𝐢𝐧𝐭𝐞𝐫𝐯𝐢𝐞𝐰 𝐭𝐫𝐚𝐢𝐧𝐢𝐧𝐠 𝐩𝐫𝐨𝐠𝐫𝐚𝐦 through whatsapp query: +91 8918633037
---------------------------------------------------------------------------------------------------------------------------------------------------------------

Рекомендации по теме
Комментарии
Автор

Understood the logic sir. Thanks a lot for all your effort in making these lectures.

chandramoulyv
Автор

i watched first 10 mins of your merge interval problem no 56 then i solved taht first and then did this one with same approach

my progression update after around 80 days of leetcode daily is crazy, solving questions even from topics i never learnt properly like graphs trees or bfs df etc etc
still a long way to go but i have a feeling i can at least solve 20 -25 problems in next month completely on my own

atharva
Автор

Actually, using the sorting technique, there is no need for two passes. Count of free days can be done during a single traversal using a single pointer:

int countDays(int days, vector<vector<int>>& meetings) {
sort(meetings.begin(), meetings.end());
int i = 0;
int count = 0;
for(auto meet: meetings) {
if(meet[0] > i + 1)
count += meet[0] - i - 1;
i = max(i, meet[1]);
}
return count += days - i;
}

alessandrocamilleri
Автор

Tried to use difference array method for range update but that led to memory overflow for a large value of days. On the same concept tried to maintain the difference array as a map but for some reason that also led to TLE (still wondering why). Sorting seemed a heavier operation at first when compared to the difference array approach but finally I see that to be accepted. This problem although so simple yet became challenging . Thanks for the solution .

adilkhot
Автор

😉❤. This was easy since I have solved similar problem.

freecourseplatformenglish
Автор

one of the most under rated thing about you is the testcase selection . It covers edge case too

Anikait-hd
Автор

Day #1
Classic merge interval problem
Solution Summary: We have to calculate free days for all 3 : at start, gaps in between schedules meetings and at the end.

DiwakarShuklaALD
Автор

var countDays = function (days, meetings) {
if (meetings.length == 0) return days;
let output = 0;
meetings.sort((a, b) => a[0] - b[0]).sort((a, b) => a[0] - b[0])
let [pStart, pEnd] = meetings[0];
output += (pStart - 1);
for (let i = 1; i < meetings.length; i++) {
let [start, end] = meetings[i];
if (start <= pEnd + 1) {
pEnd = Math.max(end, pEnd)
}
else {
output += (start - pEnd - 1);
[pStart, pEnd] = [start, end];
}
}
output += (days - pEnd)
return output
};

manoowranjith.a.j
Автор

i don't understand how the 2nd method is better. array of size n i getting broken down into 2*N and then we sort it while in the first method the size of array remains same additional O(N) is reqd for finding the intervals. I think the 1st one is better compared to 2nd one for the above program

Anikait-hd