I tried this and afterwards saw that in the hint same approach is there but still only 1 test case passed why?
But compiled successfully
using namespace std;
int main() {
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
int target;
cin>>target;
sort(arr,arr+n);
int s=0;
int e=n-1;
int sum=0;
while(s<=e){
sum=s+e;
if(target==sum){
cout<<s<<" and "<<e<<endl;
s++;
e--;
}
else if(target>sum){
s++;
}
else{
e--;
}
}
return 0;
}