we can just save the end first and then start and then use normal sort function for(int i=0;i>start>>end; v.push_back({end,start}); } sort(v.begin(),v.end()); please correct me if i am wrong
In 1:33 , the output should be 1 rather than 2. Its said that "Start time of one chosen meeting can't be equal to the end time of the other chosen meeting."
avoid doing this because usually you are not asked to write the entire code(where you'll be taking input and writing the main function) instead you'll just have to write the logic part in that case either you've to make another 2d vector and run a loop to store the end time first or you can use comaparator function, In first case you'll be using extra space that's why comaprator function is used for sorting
@@krishnakantupadhyay3053 No dear, ll n; cin >> n; vector a(n); fori(0, n) { cin >> a[i].second >> a[i].first; } sort(a.begin(), a.end()); int ans = 0; int pe = -1; fori(0, n) { if (pe
That was my first thought as well but I think it won't give the correct answer everytime. I'll attempt at giving the reason coz I'm also not sure: Why are you and me thinking about sorting by duration? That's because we think if we fill the allowed time with activities that require less amount of time then the number of activities will be maximum but if you look closely, we are assuming that we can start any activity at any time, which is not the case! Suppose, you are at t=10, and you have two options right now, either activity A1 with start=15, end=18 and another activity A2 with start=10, end=16. Now, if A1 is selected (since it has less duration) then it will occupy till t=18 and only then we'll be able to start any other activity. Whereas, if we choose A2 then it will be done till t=16!! And we can start another activity right away! Here, A1 is essentially behaving like it had start=10, end=18 Therefore, choosing A2 and thus, the activity with earlier end time is preferenced.
Can be suggest this approach is correct or not. Pseudo code Take vector of pair Sort with their starting time Prevend=vector.second Take=1 Loop(1->n) If vector.first >=Prevend then Take++ Prevend=vector.second. Basically my logic is that choose those activity which start first and you can choose those activity whose starting time is equal or more than ending time of previous activity.
the thing is that the activity can start early but may take too much time & so end late. Then your algo will fail. We want to maximize no. of jobs done in a given time frame.
ajib ho tum log bhi......agar unke paas paise nhi hoge to wo apne graphic artists, teachers ko paise kaha se dege.....tumhare liye itna bada course free me available kr diya wo tumhare liye importanat h ya fir wo paise kama rha h wo.......agar sirf ads dekh k tumhe itna bada course mil rha h so you should be thankful rather than complaining about ads.
Sir I'm beginner which is best for me Android development or full stack web development? I have some basic knowledge html and css. Plz reply 🙏? I want work from as freelancer.
Flutter or React for Android. If you want to do both web and app development. Go for React. If you only want to go for app development, Flutter is way better.
we can just save the end first and then start and then use normal sort function
for(int i=0;i>start>>end;
v.push_back({end,start});
}
sort(v.begin(),v.end());
please correct me if i am wrong
@Atul Raj it does work
@Atul Raj -_- okay
vector v;
for(int i=0;i
@@learningoverflow3138 yes it will work
@@0xsh1v4m9 it will work when u use pair not 2d vector
kya solution he sir, mja aa gya
Awesome ❤
In 1:33 , the output should be 1 rather than 2. Its said that "Start time of one chosen meeting can't be equal to the end time of the other chosen meeting."
yaha pe constraints different hai gfg se.
@@nitigyajoshi4658 constraints??
@@shivjyotigarai2141 constraints ka matlab nahi pata?
@@nitigyajoshi4658 haan. lekin usse iska kya connection haan?
Thank u bhaiya 💕💕
Rather than making a custom comparator just use vectors of pair and fill end time before the start and simply use the sort function.
avoid doing this because usually you are not asked to write the entire code(where you'll be taking input and writing the main function) instead you'll just have to write the logic part in that case either you've to make another 2d vector and run a loop to store the end time first or you can use comaparator function, In first case you'll be using extra space that's why comaprator function is used for sorting
@@krishnakantupadhyay3053 No dear,
ll n;
cin >> n;
vector a(n);
fori(0, n)
{
cin >> a[i].second >> a[i].first;
}
sort(a.begin(), a.end());
int ans = 0;
int pe = -1;
fori(0, n)
{
if (pe
anyone else with me who vibes on initial background music of apna college 😂😂😂
how this guy is even teaching,leave it man,not for u ,just blindly reading code
I sorted by end-start time, and then use the same concept as if( end
That was my first thought as well but I think it won't give the correct answer everytime. I'll attempt at giving the reason coz I'm also not sure:
Why are you and me thinking about sorting by duration? That's because we think if we fill the allowed time with activities that require less amount of time then the number of activities will be maximum but if you look closely, we are assuming that we can start any activity at any time, which is not the case!
Suppose, you are at t=10, and you have two options right now, either activity A1 with start=15, end=18 and another activity A2 with start=10, end=16.
Now, if A1 is selected (since it has less duration) then it will occupy till t=18 and only then we'll be able to start any other activity. Whereas, if we choose A2 then it will be done till t=16!! And we can start another activity right away!
Here, A1 is essentially behaving like it had start=10, end=18
Therefore, choosing A2 and thus, the activity with earlier end time is preferenced.
thanks @@spaghetti185
Please share similar problems as well.
jaldi se jaldi leni hai jo jaldi khatam ho rhi hai 😆 3:46
Web development ka course continue nhi ho rha aur c++ ka course khatm nhi ho rha
Thank you
where is job selelction problem
Thankyou bhaiya.
custom operator wala trick thick se samajh nhi aa rha hai
0:01 Heard Ok Google? 😂😁
No
No
Am I the only one who was dancing on those intro beats?
Can be suggest this approach is correct or not.
Pseudo code
Take vector of pair
Sort with their starting time
Prevend=vector.second
Take=1
Loop(1->n)
If vector.first >=Prevend then
Take++
Prevend=vector.second.
Basically my logic is that choose those activity which start first and you can choose those activity whose starting time is equal or more than ending time of previous activity.
the thing is that the activity can start early but may take too much time & so end late. Then your algo will fail.
We want to maximize no. of jobs done in a given time frame.
Bhai jaldi karna hai toh difference between start and end time kyo nahi dekhte hai joh kaam chota hoga usee jyaada hopayenge na kaam?????🙏
activity which have less end time will have less difference offcourse.
@@tarunbisht8016 no not at all
Web dev course kab continue hoga
typedef pair pair1;
struct comp {
bool operator()(const pair1 &x, const pair1 &y) const {
if (x.second != y.second) {
return x.second < y.second;
}
return x.first < y.first;
}
};
int Solution::solve(vector &A, vector &B) {
vectorarr;
for(int i=0;i
why we are using a[1] and b[1] in comparator, not a[0] and b[0] please someone explain.
bhai end time se sort kar rahe hai
Upcoming premier are khatarnak 🤩🤩but i want to learn theae in java only please explain java code also
For Java - Refer to pepcoding on TH-cam , it has complete DSA and questions explained in java
Plz explain sort line
ohh physics wala🤨
yeh a[1]
Finish time se sort kar rahe hein
I was solving the same q today
Kudh ko hi samja rahe ho kya
sorry it was a right code it's my mistaken
bhai tu padhana chod de..
Bhai samjha toh deta
bhai isse zyada kya smjhayenge vo?
samjhaya toh hai kitna acche se.
sir code which you written this is wrong because if end time same in that case we have to check the first time that's why
Jonsi = jo bhi ....Hindi bhi shi ho jayegi isse toh
This code isn't working and sorry to say but this is one of the rubbish course for c++ even basic concept bhi bhul jaoge
🔥🔥🎉💥🔥
0:01 Heard Ok Google? 😂😁
V[I][1] kyun liya plzz help
starting point ko check kara gya hai
accha kamaai ka dhanda khola h waise long term investment...
Aman be like - paisa hi paisa hoga by ads.
ajib ho tum log bhi......agar unke paas paise nhi hoge to wo apne graphic artists, teachers ko paise kaha se dege.....tumhare liye itna bada course free me available kr diya wo tumhare liye importanat h ya fir wo paise kama rha h wo.......agar sirf ads dekh k tumhe itna bada course mil rha h so you should be thankful rather than complaining about ads.
Sir I'm beginner which is best for me Android development or full stack web development? I have some basic knowledge html and css.
Plz reply 🙏? I want work from as freelancer.
Udacity for Android dev.
Flutter or React for Android.
If you want to do both web and app development. Go for React. If you only want to go for app development, Flutter is way better.
🤘🤘🤘🤘🤘
✌️♥️🔥
Second
Am I first?
No u are rishab
@@madhurmohnish ye bdhiya tha guru
@@rishabhrajrishu_ Padle...Mirzapur ke dialog me kuch nhi rakha!
@@garvtambi5786 padh le, gyan dene me kuch nhi rkha
Thank you bhaiya ❤️