https://online.codingblocks.com/app/player/69195/content/115367/5280/code-challenge
please explain this problem.
https://online.codingblocks.com/app/player/69195/content/115367/5280/code-challenge
please explain this problem.
Explanation
Example 1 :
3
10 20
12 15
20 30
Consider the above 3 activities sorted by
by finish time.
start[] = {10, 12, 20};
finish[] = {20, 25, 30};
A person can perform at most two activities. The
maximum set of activities that can be executed
is {0, 2} [ These are indexes in start[] and
finish[] ]
Example 2 :
6
1 2
3 4
0 6
5 7
8 9
5 9
Consider the above 6 activities
sorted by by finish time.
start[] = {1, 3, 0, 5, 8, 5};
finish[] = {2, 4, 6, 7, 9, 9};
A person can perform at most four activities. The
maximum set of activities that can be executed
is {0, 1, 3, 4} [ These are indexes in start[] and
finish[] ]
Approach
idea is to use 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.
Algorithm
i hope this helps
if yes hit a like and don’t forgot to mark doubt as resolved
if you have more doubts regarding this feel free to ask