Arrays- Target Sum Triplet

TestCase is wrong, I thnk because of time complexity. #include
#include
using namespace std;

int main() {
int n;
int arr[n];
cin>>n;

for(int i=0; i<n;i++){
cin>>arr[i];
}
int target;
cin>> target;
for(int i=0; i<n; i++){
for(int j=i+1;j<n;j++){
if(arr[j]<arr[i]){
int temp;

         temp=arr[i];
		            arr[i]=arr[j];
         arr[j]=temp;
     }
   }
  }

for(int i=0; i<n; i++){
for(int j=i+1;j<n;j++){
for(int k=n-1;k>= i+2;k–){
if((target-arr[i])== (arr[j]+ arr[k]))
{
cout<<arr[i]<<", “<<arr[j]<<” and "<<arr[k]<<endl;
}
}
}
}

return 0;

}

Hi @samk86676
Time complexity of your approach is large.
Basically you have to use a hash based approach to solve this ques.

  1. Fix the first element as A[i]
  2. Find pair in subarray A[i+1…n-1] with sum equal to sum - A[i] using hash map.