Activity selection problem

I am unable to understand the solution from editorial

hello @soumyabhardwaj75

the idea for this problem is simple.
u always need to pick that activity which has less finish time ,it is becuase then we will have more time to finish other activites.

so first sort the acitivities based on the ending time.
and then pick activitiy which has least ending time and then pick next acivitiy which has starting time more than ending time of last picked
and repeat the same on remaining activities

for code refer this->

What is this argc and argv

that is command line argument, ignore it.
u can simply use

int main(){

}

Can you please explain the code by writing comments

Can u plz explain it from line 25? How are we choosing the first activity ?

after sorting , the activity present at index 0 will the the first required activity

Hey ? M still not able to understand the code

dry run it on some sample test cases.

or refer greedy playlist of ur course, this problem might be covered in that playlist

1 Like

ok now i got it . Thanks

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.