Activity Selection Question Explain

Please explain the question once, did’nt get how the output was 2 .
Is this like the 0th activity started at 10 and ended at 20 and the 2nd activity started at 20 and ended at 30 so maximum time was consumed here.
OR is it according to difference in maximum time spend, don’t know, clarify it once please.

Hello @Sakshi2004
in this you should take the input in the pair format and then sort the pairs according to their ending time and then you can check if the ending time of the current meeting is greater then the starting time of the next meeting then you need to increment the counter.
Here for your reference i am attaching the code:


if you have any doubt you can ask here
Happy Learning!!

In this the trick is to keep the track of the previous ongoing meeting and to check the time with the ending of that.

Yeah, Thanks for explanation.

@Sakshi2004 you can mark this as resolved.
Happy Learning!!

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.

Can you please explain what is fixed and setprecision used there?

And what is the mistake in the code- https://ide.codingblocks.com/s/408258, coz I am unable to find any mistake here. Please don’t give the updated code of yours that I have seen and please clarify the mistake there in the code.

Ok. I got my mistake. Just tell the last line in main function in your updated code?