Correct answer is not being accepted

prob:https://hack.codingblocks.com/app/contests/1975/1003/problem
sol: https://ide.codingblocks.com/s/388344

The implementation you have applied is not ideal for Pair of Roses problem
Let me tell you how to do it,
Take input then sort the array
For eg:
5
10 2 6 8 4
10

After sorting it will be
2 4 6 8 10
Now place i at 2 and then iterate from 4 till remaining part of the array, when you find a[i]+a[j]==10, print it and break
Now you will also have to keep this in mind that what if target value is 12, in that case you have to leave value 2 and have to consider 4 and 8 by iterating i. This is a 2 pointer problem. Try to code it. If you won’t be able to solve it then let me know i will give you code for this :slight_smile:


I have solved it using 2 pointer approach please run and check

Have you done target sum pair problem @raghav007 ?

yes I have done the target sum pair problem

So it’s the same problem, do what find all the tagetted values and after that store their indexes in an array and find that pair whose difference is minimum.

thanks now it is solved

I am marking it as resolved @raghav007 do give your feedback

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.