Getting a compilation ERROR!, on Activity Selection Problem

Can’t figure out the ERROR in my code. Please Help!

Here is my code

hi @swastikswarupmeher can you explain your approach a bit so I can debug the program better? I have figured out 2-3 errors but it is still giving a compilation error so I’d like to know the approach you are using.
The errors I have figured out till now are:

  1. here it is an iterator of a certain type, so you should assign appropriate values to it. image
  2. Your compare function should compare values according to the ending time of activities.
  3. You did not send the address of compare function in the sort function.

@Ishitagambhir I have updated my code with your first suggestion and commented out the approach.
Here is my updated code.

I have explained my point for your second suggestion in the code itself . and for the third suggestion, I am sorting the activities according to the starting time and by default sort function sort a vector of pair according to the first element of the pair. So no need to send comp function for that sort part.

All the above approach are according to my knowledge, and approach. Maybe I am wrong. Please let me know if any wrong approach I have followed. and please help for the COMPILATION ERROR.

Thanks!

hi @swastikswarupmeher the approach of comparing the activities according to their starting time is wrong. There are cases where it wont work.
Fo eg you have activities like: 1-5, 2-3, 3-4
Now according to me we can perform 2 activities, 2-3 and 3-4
But if your approach is to be followed, then only 1 activity will be performed, ie 1-5

The correct approach is to sort the activities according to their ending time and choose the activities greedily.

1 Like

@Ishitagambhir ohh! got it thanks. Now can you help me with the compilation error?

@swastikswarupmeher you need to change the approach by which you are choosing the activities. A simple for loop should suffice. Keep track of the last activity you chose and compare the ending time of that activity with the currect activity you are iterating. If the current activity is not overlapping, update the count and last activity performed to be the current activity

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.