even after finding the sum equals to target i am not increasing the i value and not decreasing the j value by 1
still i am getting the right answer and passsed all test cases
but as u taught us that u have to increase and decrease the value of i and j by 1;
code:
using namespace std;
#include
#include
int main()
{
int n,target;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
cin>>target;
sort(a,a+n);
int i=0,j=n-1;
while(i<j)
{
if((a[i]+a[j])==target)
{
cout<<a[i]<<" and "<<a[j]<<endl;
//i++;
//j--; //doubt ??
}
if((a[i]+a[j])<target)
i++;
else
j--;
}
}