can u explain its logic
What is wrong in my code
hi @dhanu9721, your code is not correct as in your code you are increasing count whenever l>s , which is not the case for every case as you can encounter a case in which the starting time of an activity is after the previous activity but the finishing time is too large ,enough for two or more task with greater starting time to be accomodated ,
so what you need to do is,
you have to choose the task optimally, this question is a classic example of a greedy algorithm
So, let me explain,
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 print it.
How does Greedy Choice work for Activities sorted according to finish time?
Let the given set of activities be S = {1, 2, 3, …n} and activities be sorted by finish time. The greedy choice is to always pick activity 1.
How come the activity 1 always provides one of the optimal solutions. We can prove it by showing that if there is another solution B with the first activity other than 1, then there is also a solution A of the same size with activity 1 as the first activity. Let the first activity selected by B be k, then there always exist A = {B – {k}} U {1}.(Note that the activities in B are independent and k has smallest finishing time among all. Since k is not 1, finish(k) >= finish(1)).
I have commented the code for better understanding
code : - Click here for the code
In case of any doubt feel free to ask 
Mark your doubt as RESOLVED if you got the answer