i am not able to identify the problem in this code
Please help to solve the problem
your approach is wrong. think about the case when an activity has lowest starting point and highest ending point, but there are many activities that can be performed one by one.
for eg. there are 4 activities with following start and end point
4
1 34
1 2
3 4
5 6
your approach will give answer as 1. Moreover your code for finding min and max end points is also incorrect as you are comparing indices instead of values.
Right approach:
1.sort activities based on their finishing time
2.select first activity with least finish time, count++, say its value is stored in latest_finish variable
3.
a.from remaining activities select activity with start time greater than or equal to latest_finish value and with lowest finish time
b. update latest_finish to finish time of selected activity
c. count++
4. repeat step 3 with remaining activities
5. print count
thanks
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.