Arrays-Target Sum Triplets

#include
#include

using namespace std;
int main()
{
int n,target;
cin>>n;
int arr[n];
for(int i=0;i<n;i++)
{

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

    }
return 0;

}
plz tell the mistake am not able to find it!!

@ashigupta.gupta570 hey ashi please share code through coding blocks ide

i have put it on collaborated mode .

@ashigupta.gupta570 hey ashi please share your code through coding blocks ide because my collaborated mode is creating problem

@ashigupta.gupta570 use three loops to print triplet

why so ??
i dont understand!!!

@ashigupta.gupta570
for(i=0;i<n-2;i++)
{
for(j=i+1;j<n-1;j++)
{
for(k=j+1;k<n;k++)
{
if(a[i]+a[j]+a[k]==target)
{
cout<<a[i]<<", “<<a[j]<<” and "<<a[k]<<endl;
}
}
}

sir this is of n3 complexity
with my logic i am using just one loop and its working too but not getting further iterated .
can u plz tell correction in my logic .
this logic which i have used is basically what we have been told in the hint video !!!

plz tell whats wrong in this

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.