O(n) approach used


#1

bool cmp(vector A, vector B){
return A[1]<B[1];
}
int Solution::solve(vector<vector > &A) {
int count = 1;
sort(A.begin(), A.end(), cmp);
int endtime = A[0][1];
for(int i = 1 ; i < A.size() ; i++){
if(A[i][0] > endtime){
count++;
endtime = A[i][1];
}
}
return count;
}


#2

But you’re sorting the intervals which will take O(nlogn).