Code not working for -ve inputs

this is my code for array-target sum

what error you are getting


for size: 5
array: 2 -7 0 5 3
tarsum:5
it is giving op 0 and 5 , 2 and 3 but not 2 and -7

how it will give 2 and -7 as sum will be -5 not 5

So I am unable to figure out what’s wrong in my code it’s working for -ve values as well. It passed 2 test cases out of 4 please help!

you just need to sort the array before calling the function.everything else is fine