Activity Selection Problem - Greedy Algorithm | C++ Placement Course | Lecture 33.3

preview_player
Показать описание
Notes of this Lecture:
Рекомендации по теме
Комментарии
Автор

we can just save the end first and then start and then use normal sort function
for(int i=0;i<n;i++){
int start, end;
cin>>start>>end;
v.push_back({end, start});
}
sort(v.begin(), v.end());
please correct me if i am wrong

learningoverflow
Автор

Rather than making a custom comparator just use vectors of pair and fill end time before the start and simply use the sort function.

sameerraj
Автор

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."

shivjyotigarai
Автор

how this guy is even teaching, leave it man, not for u, just blindly reading code

utkarshgautam
Автор

anyone else with me who vibes on initial background music of apna college 😂😂😂

AryanSharma-zljf
Автор

I sorted by end-start time, and then use the same concept as if( end<=activity[i][start] ) then take++; end=activity[i][end] ; is this sorting aprroach correct w.r.t to the original question? by considering their difference of duration, i assume to take those tasks with less duration and thus maximizing final ans.

anoopsaxena
Автор

Please share similar problems as well.

arpit
Автор

jaldi se jaldi leni hai jo jaldi khatam ho rhi hai 😆 3:46

sahajpatel
Автор

Web development ka course continue nhi ho rha aur c++ ka course khatm nhi ho rha

thecaptaman
Автор

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.

manishmalhotra
Автор

Bhai jaldi karna hai toh difference between start and end time kyo nahi dekhte hai joh kaam chota hoga usee jyaada hopayenge na

albinthomas
Автор

custom operator wala trick thick se samajh nhi aa rha hai

upasanapan
Автор

Upcoming premier are khatarnak 🤩🤩but i want to learn theae in java only please explain java code also

ritik
Автор

Am I the only one who was dancing on those intro beats?

VAIBHAVMALHOTRA
Автор

why we are using a[1] and b[1] in comparator, not a[0] and b[0] please someone explain.

MANPREETSINGH-fthd
Автор

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

abhishekrajora
Автор

Jonsi = jo bhi ....Hindi bhi shi ho jayegi isse toh

punitmaheshwari
Автор

sorry it was a right code it's my mistaken


abhishekrajora
Автор

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.

gogi-tech
Автор

typedef pair<int, int> 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<int> &A, vector<int> &B) {
vector<pair1>arr;
for(int i=0;i<A.size();++i)
{
arr.push_back({A[i], B[i]});
}
sort(arr.begin(), arr.end(), comp());
int take=1;
auto end=arr[0].second;
for(int i=1;i<A.size();++i)
{
auto temp=arr[i];
if(temp.first>=end)
{
take++;
end=temp.second;
}
}
return take;
}

adarshraj