What is problem in my current code

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define INF 50000000000009999ll
using ld = long double;
using ull = unsigned long long;
bool cmp(pair<ll,ll> a,pair<ll,ll> b)
{
if(a.first==b.first)
return a.second < b.second;
return a.first < b.second;
}
void solve(vector<pair<ll,ll>> arr,int n)
{
sort(arr.begin(),arr.end(),cmp);
ll cur=arr[0].second,cnt=1;
for(int i=1;i<n;i++)
{
if(arr[i].first >= cur)
{
cur=arr[i].second;
}
else
cnt++;
}
cout<<cnt<<"\n";
}
int main()
{
int t;
cin>>t;
while(t–)
{
int n;
cin>>n;
vector<pair<ll,ll>> arr(n);
for(int i=0;i<n;i++)
cin>>arr[i].first>>arr[i].second;
solve(arr,n);
}

return 0;

}

@sachinkumar24051999 there are couple of small mistakes in your code

  1. you need to sort by the ending time so in the cmp function correct if condition is if( a.second != b.second )
  2. in the solve function the if statement signifies that you have taken the next task so cnt++ needs to be with if not in the else statement

Here is rectified code

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.