Array Target Sum pairs

why this code not passing all test cases?

#include
#include <bits/stdc++.h>
using namespace std;

#define ll long long int
ll arr[1005];
int n;
bool dp[1005][1005];
ll target;
void print_target_Sum(int left, int right)
{
if(left >= right)
{
return;
}
if(dp[left][right])
{
return;
}
if(arr[left] + arr[right] == target)
{
dp[left][right] = dp[right][left] = true;
cout<<min(arr[left] , arr[right])<<" and "<<max(arr[left] , arr[right])<<endl;
}
print_target_Sum(left , right-1);
print_target_Sum(left+1 , right);
print_target_Sum(left+1 , right-1);
}
int main()
{
cin>>n;
for(int i = 0 ; i < n ; i++)
{
cin>>arr[i];
}
cin>>target;
sort(arr , arr+n);
memset(dp , 0 , sizeof dp);
print_target_Sum(0 , n-1);
return 0;
}

Note that you have to “Print each pair in increasing order.” It is given in the question. Also Dp is not required here. You can simple solve this using the two pointer approach after sorting the elements.
Try it again. Next time onwards please save your code on ide.codingblocks.com and then share its link . It is easy for us to debug there.

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.

yes thank you sir … it meant lot to me …