Different position of comparator function gives timeout, anyone explain?
First I place comparotor function inside the Solution class in public scope by making the comparator function static, it is giving TLE.\nThen I go through the o
First I place comparotor function inside the Solution class in public scope by making the comparator function static, it is giving TLE.\nThen I go through the other solutions and put the comparator function in different structure now code is working fine. Can anyone please explain?\n\n```\nstruct cmp {\n    bool operator()(vector<int>& node1, vector<int>& node2) {\n        if(node1[1]==node2[1])\n            return node1[0] < node2[0]; \n        return node1[1] < node2[1];    \n    }\n};\n\n\nclass Solution {\n    \npublic:\n    \n    // static bool comp(vector<int> a, vector<int> b) {\n    //     if (a[1] == b[1])\n    //     {\n    //         return a[0] < b[0];\n    //     }\n    //     return a[1] < b[1];\n    // }\n    \n    int maxTwoEvents(vector<vector<int>>& events) {\n        \n        sort(events.begin(), events.end(), cmp());\n        vector<int> maxTill(events.size());\n        \n        int maxVar = 0;\n        \n        for(int i=0; i<events.size(); i++)\n        {\n            maxVar = max(events[i][2], maxVar);\n            maxTill[i] = maxVar;\n        }\n        \n        int ans = 0;\n        \n        for(int i=0; i<events.size(); i++)\n        {\n            \n            int index = binarySearch(events, 0, i-1, events[i][0]) ; \n            if(index>=0)\n            {\n                ans = max(ans, events[i][2] + maxTill[index]);\n            }\n            else\n                ans = max(ans, events[i][2]);\n                \n        }\n        \n        return ans;\n        \n    }\n    \n    int binarySearch(vector<vector<int>>& events, int left, int right, int target)\n    {\n        while(left<=right)\n        {\n            int middle = left + (right - left)/2; \n            if(events[middle][1]>=target)\n            {\n                right = middle-1; \n            }\n            else\n            {\n                left = middle+1; \n            }\n        }\n        return right; \n        \n    }\n};\n```\n\nHere when I use the commented function` static bool comp ` in sort function as `sort(events.begin(), events.end(), comp)` it gives TLE.\n
['C', 'Sorting', 'C++']