what is wrong with this code?
Target Sum triplet
Hi @nirupama1
After sorting the array you are using loop and if conditions in a wrong way. It should be implemented as follows :
Have a look at it.
why can’t i use the while loop and if statement like that?
Hi @nirupama1
In your code you are first finding a pair whose sum < k but remember the numbers of array can be negative or zero also. So in the if statement of a[l]+a[j]==k then can be a 0 in array which you are not searching. And also when a[i]+a[j] > k then there can be a negative number which when added to this can result sum as k.
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.