In target sum pair question I can't pass test case 0, no idea why? HELP


–link to my code

the pair has to be of unique numbers.like for
5
5
2
3
4
1
6

3+3 wont be correct

I also watched the hint video but now I am not able to pass test case 1 now!!!----https://ide.codingblocks.com/s/181372---link to my code, PLEASE HELP AS SOON AS POSSIBLE

I’ve checked this case as well and my answer is correct , my doubt is that I cant reduce my time how should I do it.
first i tried the question by brute force then test case 0 stucks!!–https://ide.codingblocks.com/s/181334
then i tried the question by sorting array and then calling the function for finding sum pairs then test case 1 stucks!!—https://ide.codingblocks.com/s/181372

@Yuvraj_Luhach
for your brute force you did not have to take the same element again so 3+3 woud not be answer for 6 as a sum .for that start you for loop for j from i+1 ,not i in line 14

for when u are forming an array and sorting it to call sum ,You have not included when the array value might be any negative integer.
just add
else
lo++;

after your else if condition for when a[lo]+a[hi] <c

please mark your doubt as resolved,if u are satisfied with the answer :slight_smile:

could you please provide me code I am unable to understand it clearly OR you can make changes in my code

@Yuvraj_Luhach i have made the corresponding changes to your code

THANKS FOR RESOLVING MY DOUBT, are you also doing the Java Master course -Crux ??

I’m the TA for your course.
Please mark your doubt as resolved if you are satisfied with the solution.:slight_smile: