Getting TLE with the same code as in the solution!


Comment body goebool check(vector a,vector b){

return a[1]<b[1];


int Solution::solve(vector<vector > &a) {

if(a.size()==0) return 0;


int l=a[0][1];
int ans=1;


for(int i=1;i<a.size();i++){
    if(a[i][0]<=l) continue;
return ans;

s here.


Try to use check(vector &a,vector &b )return a[1]<b[1]; instead off check(vector a,vector b)return a[1]<b[1];
because first is pass by reference and second in a pass by value, pass by value takes more time as compare to pass by reference because in a pass by value function create a copy of pass element in our case which is two vector.

I hope this might help you


If you are getting TLE, use the following custom comparator function for sorting the array
bool cmp(vector < int > a,vector < int > b)
if(a[1]!=b[1]) return a[1]<b[1];
return a[0]<=b[0];