Activity Selection Problems

unable to understand the problem

You are not able to understanfd the problem
or how to solve it?

hi @bhattanurag426 , problem statement is : -
You are given n activities (from 0 to n-1) with their start and finish times. Select the maximum number of activities that can be performed by a single person, assuming that a person can only work on a single activity at a time.

here since the person can only work on a single activity at a time thus he can;t do two activities that overlap with each other , i can better explain u with some examples

Example 1

3 //no of activities
10 20 // time intervals of activities (start time - end time)
12 15
20 30

here, ans=2,as the person can perform two activity
as the person can;t perform activity 1 and 2 together as if he chooses activity 1 then he will be busy from 10-20 so he can;t pick the activity that starts between the interval but he can choose activity 3 as it starts the same time activity 1 terminates. similarly he can choose activity 2 and 3

6
1 2
3 4
0 6
5 7
8 9
5 9

A person can perform at most four activities. The
maximum set of activities that can be executed
is acivity {1, 2, 4, 5}

In case of any doubt feel free to ask :slight_smile:
If you got the answer then mark your doubt as resolved

1 Like

not working for other test cases

hEY @bhattanurag426

sir what is the reason for applying sorting on the bases of end time

You are picking greedily but that won’t work if end time are not sorted
Assume this

Here change the order and then apply greedy will that work ?

ok sir i understood

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.