Activity selection problem

question–>


code–>

class Solution {
public:
    bool compare(vector<int> &v1, vector<int> &v2){
        return v1[0]<v2[0];
    }
    int maxEvents(vector<vector<int>>& events) {
        sort(events.begin(),events.end(),compare);
       int count=0;
        for(int i=0;i<events.size();i++){
            if(events[i][0]>=events[i-1][1]){
                count++;
            }
        }
        return count;
    }
};

it is showing this error for the custom compare function
line 7: Char 42: error: reference to non-static member function must be called
sort(events.begin(),events.end(),compare);
^~~~~~~
1 error generated.
help!!

@tusharaggarwal272 can see my code what is wrong

Hello @sheikhhaji18 you have to use static keyword before the bool compare:


please see this:
but your approach is still falling.
try to implement any other logic and then we will discuss.
the same question is there on hackerblocks as well.
you should try that as well.
Happy Learning!!

@tusharaggarwal272 my code is not passing the test on hackerblocks
question–>
https://hack.codingblocks.com/app/contests/1617/408/problem
code–>

Hello @sheikhhaji18
sort the pairs according to their ending time and then you can check if the ending time of the current meeting is greater then the starting time of the next meeting then you need to increment the counter.
Here for your reference i am attaching the code:


if you have any doubt you can ask here
Happy Learning!!

*ending time previous meeting is less than that of the current meeting,it passed all testcasses on hackerblocks thanks

my code only passes 5 testcases but i applied same logic as the activity problem,in that leetcode question the person can do all task that has same starting and ending point right?

Hello @sheikhhaji18 yes right .

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.