targetsumProblem

one of my test cases isn’t working right

#include
#include
using namespace std;
int main() {
int n;
cin>>n;
int arr[1001];
for(int i=0;i<n;i++)
cin>>arr[i];
int target;
cin>>target;
sort(arr,arr+n);
int left=arr[0];
int right=arr[n-1];
int sum=0;
while(left<right){
sum= left+right;
if(sum>target){
cout<<left<<" and "<<right;
cout<<endl;
}
if(sum<target){
left++;
}
else
right–;

}
return 0;

}

Hi ritika
pls share your code on ide

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.