Example tc is passing but getting 0

Please check my code and explain, what’s wrong with my code ?

Hey @tgoel5884
Your approach is incorrect
it worked on given testcase because its already sorted acc to end times

Correct Approach :
sort the activities in the increasing order of their finishing times. Initially, we choose the first activity. Now, starting from second activity, current activity can be selected if the finish time of previous selected activity is less than or equal to the starting time of current activity.

U just have to apply sorting make u sure u are also updating start time after sorting acc to end time
you have to use custom class or pairs array

1 Like

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.