Activity Selection Problems

if am not wrong, then the ques are to compare 2 elements that take max time to complete a task and find how many activities take max time??

if ā€˜nā€™ is equal to 3 then how can we compare with 2 numbers ??

or should I keep array size different maybe 2

ques:- https://online.codingblocks.com/app/player/189104/content/180064/5280/code-challenge

Correct Approach

you have to use solve this by greedy Algorithm.
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.

  1. Sort the activities according to their finishing time
  2. Select the first activity from the sorted array and print it.
  3. 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