Can't pass one test cases

#include
#include
#include
using namespace std;

int max_activity(vector<pair<int,int>> v,int n)
{
sort(v.begin(),v.end());
int ans = 1;
int j = 0;
for(int i=1;i<n;i++){
if(v[i].second >= v[j].first){
ans++;
j++;
}
}
return ans;
}

int main() {
int t;
cin>> t;
int n;
while(t–){
cin>> n;
vector<pair<int,int>> v;
for(int i=0;i<n;i++){
int start,end;
cin>> start>> end;
v.push_back({end,start});
}
cout<< max_activity(v,n)<<endl;
}
return 0;
}

hi @sroy3166 in this part, i think you are storing the last activity chosen in the variable j…if so, then instead of doing j++, you should do j = i

yeh…thanks a lot…thanks for helping

1 Like

@sroy3166 dont forget to mark the doubt as resolved!