Why is other testcase not working

#include
using namespace std;

void timefor(int first[],int last[],int n)
{
int c=0;
for(int i=0;i<n;i++)
{
if(first[i]>=last[i])
{
c++;
}

}
cout<<c<<endl;

}
int main()
{
int testcase;
int n;
cin>>testcase;

for(int i=0;i<testcase;i++)
{
cin>>n;
int first[n];
int last[n];
for(int i=0;i<n;i++)
{
cin>>first[n]>>last[n];

}
timefor(first,last,n);

}

return 0;
}

@muditak14 i think you need to first sort the array according to there finish time then running these logic will work fine.

hi @muditak14 you need to sort the activities according to their ending time and greedily choose non-overlapping activities

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.