Unable to pass all the testcases
Unable to pass all the testcases
@1997gautam.shah you have to display the three numbers in increasing order. did you take care of this condition?
yes
#include<bits/stdc++.h>
using namespace std;
void triplet (int a[],int n, int sum)
{ sort(a,a+n);
for(int i=0;i<n-2;i++)
{int j=i+1;
int k=n-1;
while (j<k)
{
if (a[i]+a[j]+a[k]<sum)
j++;
if (a[i]+a[j]+a[k]>sum)
k--;
if ((a[i]+a[j]+a[k])==sum)
{
cout<<a[i]<<", "<<a[j]<<" and "<<a[k];
j++;
k--;
cout<<endl;
}
}
}
}
int main() {
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
int sum;
cin>>sum;
triplet(a,n,sum);
return 0;
}
I have given the condition while (i<j) so it should not print 1 2 2
I have try that, According to me It should not be the ouput. Please help me to understand the error.
@1997gautam.shah corrected you have to use if else if
bro is it clear now?
if yes dont forget to hit like and mark resolved 
Ok got it! Thankyou 
Done…