I have made this code but this does not run for all test cases. But the test cases I have tested, it works well for them.
Here goes my code::
#include
using namespace std;
int main() {
int a[1000];
int n, target;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
cin>>target;
int left =0;
int right = n-1;
while(left<right)
{
if((a[left]+a[right] == target) || (left==right))
{
cout<<a[left]<<" and "<<a[right]<<endl;
left +=1;
right = n-1;
}
right -=1;
}
return 0;
}
Please tell me what is to be improved in this code.