Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code for Activity selection problem #1408

Merged
merged 1 commit into from
Sep 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions 238 Activity Selection [GREEDY].txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
int maxMeetings(int start[], int end[], int n)
{
vector<pair<int,int>> vpair; // making pair and sorting acc. to end time
for(int k=0;k<n;++k){
vpair.push_back(make_pair(end[k],start[k])); //pushing 'end time' first because we need
} // to sort according to end time
sort(vpair.begin(),vpair.end()); //since sort will occur with first value of the pair


int i=0; //iterator for previous activity
int count=1; // since activities are sorted according to finish time first activity will always be considered by default
for(int j=1;j<n;++j){ // iterator for current activity
if(vpair[j].second>vpair[i].first){ // start time of current activity shud be > than finish
i=j; //time of prev activity(not equal since stated in q.)
count++; //prev activity i now is equal to current activity 'j'
} //since we move to search next activity
}
return count;



}