Target sum triplets.cpp

showing no output for 2nd testcase
code is
#include
#include
using namespace std;
int main() {

int n,key;
cin>>n;
int arr[n];
for(int k=0;k<n;k++)
cin>>arr[k];

cin>>key;
sort(arr,arr+n);

int* l =0;
int* r=0;
int i=0;
while(i<n)
{l=arr+i+1;
r=arr+n;
while(l<r){
 if(key<arr[i]+*l+*r)
 {
     r--;
 }
 if(key>arr[i]+*l+*r){
 l++;
 r--;
 }
 else if(key==arr[i]+*l+*r){
 cout<<arr[i]<<", "<<*l<<" and "<<*r<<endl;
 l++;
 r--;
 }

}
i++;
}
}

@ayush1213 hey ayush your code is not working for this case
3
1
3
2
6

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.

@ayush1213 hey ayush is that any issue with this