Hint required for this problem

Please provide some hint in order to solve this problem. I’m stuck at this. Its a greedy algo question and I’m not familiar with it.

The greedy choice is to always pick the next activity whose finish time is least among the remaining activities and the start time is more than or equal to the finish time of previously selected activity. We can sort the activities according to their finishing time so that we always consider the next activity as minimum finishing time activity.

Sort the activities according to their finishing time
Select the first activity from the sorted array and print it.
Do following for remaining activities in the sorted array.
a) If the start time of this activity is greater than or equal to the finish time of previously selected activity then select this activity and count it

Reference Code

1 Like