I solved the problem by first sorting the array and then using two pointer approach I also used the method similar to one given in the hint but still I am unable to solve one test case. I also used the same condition as we always used, I am unable to identify the test case which is giving wrong answer. How can I identify test cases more effectively ?
UNABLE TO IDENTIFY TEST CASES IN PAIR WISE SUM PROBLEM
hEY @tardev00
There is only one correction in ur code and mentioned that in comments
You will be able to formuate test cases on ur own once u are comfortable with the logic of problem
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int m;
cin>>m;
int a[m];
for(int i=0; i<m; i++){
cin>>a[i];
}
int target=0;
cin>>target;
sort(a,a+m);
int i=0, j=m-1;
while(i<j){
if(a[i]+a[j]==target){
cout<<a[i]<<" and "<<a[j];
cout<<"\n";
i++;
j--;//ONLY CORRECTION : j-- here
}
else if(a[i]+a[j]>target){
j--;
}
else if(a[i]+a[j]<target){
i++;
}
}
return 0;
}