Another way to think about this is to sort by start time in asc order. While keeping track of lastEnd time, when evaluating times[i] , there are 2 cases 1. there is no overlap; - update lastEnd time to times[i][1] - count++ 2. there is an overlap ( times[i][0]
@takeUforward I have a question regarding this. Why minimum platform doesnt work here? I mean if I try to calculate minimum meeting rooms and then assign 1 meetings to each of one rooms and rest to just one room
Simple Java Code For Only Meeting Count: class Meeting{ int start; int end; public Meeting(int s, int e){ this.start=s; this.end=e; } } class Solution { public static int maxMeetings(int start[], int end[], int n) { List meetings = new ArrayList(); for(int i=0; i m.end)); int lastEnd= -1; int count=0; for(Meeting meet: meetings){ if(meet.start > lastEnd){ lastEnd=meet.end; count++; } } return count; } }
int maximumMeetings(vector &start, vector &end) { vector v; int n = start.size(); for(int i=0;i time) { ans++; time = item.second; } } return ans; } int this code , i dont need to store the position anywhere , just store both of those in a vector of pairs, i think this code is better than the given video
As you said sort the array based on meeting timing, and process the problem of sorting values, for example if the shortest meeting starts at 20 and other meeting timings are lesser than 20, how would this approach work?
this might not work for the case in which there is no 0-5 and no 1-2 and it has 0-2 removing the two inputs which are 0-5 and 1-2 and adding the input 0-2 will it work or not clarify it
Easy java solution: public static int maxMeetings(int start[], int end[], int n) { List list = new ArrayList(); for(int i=0;i lst.get(2))); int freeTime = 0; int count = 0; for(int i=0;i
C++ CODE struct meet{ int start; int end; }; class Solution { public: // Function to find the maximum number of meetings that can // be performed in a meeting room. static bool comp(meet m1,meet m2){ return m1.end
static class meeting{ int start; int end; public meeting(int s,int e){ this.start=s; this.end=e; } } public static int maxMeetings(int start[], int end[], int n) { meeting m[]=new meeting[n]; for(int i=0;ia.end-b.end); int count=0; int prev=0; int s=0; int e=0; for(int i=0;im[prev].end){ // count++; // prev=i; // } if(m[i].start>e){ count++; e=m[i].end; } } return count; }
Kijiye Meeting Meeting, karte rahiye meeting meeting, alhua meeting meeting
🤣
Its not halua meeting , its alhua (sweet potato )
@@tusharyadav5874 Ouhh, I just went with the feel😂
i could solve it using the overlapping intervals concept, felt great lol
Another way to think about this is to sort by start time in asc order.
While keeping track of lastEnd time, when evaluating times[i] , there are 2 cases
1. there is no overlap;
- update lastEnd time to times[i][1]
- count++
2. there is an overlap ( times[i][0]
understood, thanks for the perfect explanation
I am feeling like intuition is missing in this problem... does anyone same like me?
Thank you
Such a great explanation !
Goat is back
Yayyy!
Sir please start making videos on strings and stacks
How can u say that greedy will always work
@takeUforward I have a question regarding this. Why minimum platform doesnt work here? I mean if I try to calculate minimum meeting rooms and then assign 1 meetings to each of one rooms and rest to just one room
Understood
Please also include code explanation in c++ which you used to do, that would be really helpful!
Hey Bengali. Which college currently are you in?
Waiting for strings playlist
a better code
static bool cmp(pair a,pair b){
return a.second
Simple Java Code For Only Meeting Count:
class Meeting{
int start;
int end;
public Meeting(int s, int e){
this.start=s;
this.end=e;
}
}
class Solution
{
public static int maxMeetings(int start[], int end[], int n)
{
List meetings = new ArrayList();
for(int i=0; i m.end));
int lastEnd= -1;
int count=0;
for(Meeting meet: meetings){
if(meet.start > lastEnd){
lastEnd=meet.end;
count++;
}
}
return count;
}
}
tysm sir
understood
int maximumMeetings(vector &start, vector &end)
{
vector v;
int n = start.size();
for(int i=0;i time)
{
ans++;
time = item.second;
}
}
return ans;
}
int this code , i dont need to store the position anywhere , just store both of those in a vector of pairs, i think this code is better than the given video
It's not better, as the space complexity is now O(n^2) rather than O(n) in the solution
@@after_dark_777 bro space complexity is O(2n) not O(n^2)
As you said sort the array based on meeting timing, and process the problem of sorting values, for example if the shortest meeting starts at 20 and other meeting timings are lesser than 20, how would this approach work?
Sorting on basis of ending times, not on the actual length.
Thanks
this might not work for the case in which there is no 0-5 and no 1-2 and it has 0-2
removing the two inputs which are 0-5 and 1-2 and adding the input 0-2 will it work or not clarify it
Striver after eating mummy ke haath ka khaana abhi kitne video banane hai bana lenge sab hojayega ,welcome back
std :: cout
return "so_what";
Stacks
Why is
Bcoz it is given in problem statement that the start time of other meeting cannot be equal to end time of prev meeting..it must be greater
Easy java solution:
public static int maxMeetings(int start[], int end[], int n)
{
List list = new ArrayList();
for(int i=0;i lst.get(2)));
int freeTime = 0;
int count = 0;
for(int i=0;i
C++ CODE
struct meet{
int start;
int end;
};
class Solution {
public:
// Function to find the maximum number of meetings that can
// be performed in a meeting room.
static bool comp(meet m1,meet m2){
return m1.end
static class meeting{
int start;
int end;
public meeting(int s,int e){
this.start=s;
this.end=e;
}
}
public static int maxMeetings(int start[], int end[], int n)
{
meeting m[]=new meeting[n];
for(int i=0;ia.end-b.end);
int count=0;
int prev=0;
int s=0;
int e=0;
for(int i=0;im[prev].end){
// count++;
// prev=i;
// }
if(m[i].start>e){
count++;
e=m[i].end;
}
}
return count;
}
struct Meeting{
int start;
int end;
int pos;
};
bool meetingComparator(Meeting m1, Meeting m2) {
if(m1.end < m2.end)
return true;
else
return false;
}
class Solution {
public:
int maxMeetings(int n, int start[], int end[]) {
vector meetings(n);
for(int i = 0; i < n; i++){
meetings[i].start = start[i];
meetings[i].end = end[i];
meetings[i].pos = i+1;
}
sort(meetings.begin(), meetings.end(), meetingComparator); // sort according to the end time..
int freetime = meetings[0].end;
int count = 1;
for(int i = 1; i < n; i++){
if(freetime < meetings[i].start){
count++;
freetime = meetings[i].end;
}
}
return count;
}
};
Understood
Understood