I am pretty sure my logic is correct but getting wrong answer.
I just modified merge sort according to the problem.
This is my implementation
Pair of Roses Problem,Wrong answer
Hey @alampallyvinith buddy
You just need to need to use a hashamp in this
Put all array elements in hashmap
Then iterate over array and find sum-arr[i] in hashmap
If multiple answers come find pair where diff between arr[i] and sum-arr[i] is min
Hope this helps
If your query is resolved please close it
1 Like
@Aarnav-Jindal-1059677350830863 I already submitted the logic you told but I just want to know where this logic is going wrong. [logic is while merging I am find the pair and getting the minimum].If it gives TLE then I will be happy.
@alampallyvinith
The issue is with line 12
You assumed a[j] > a[i]
you should have used abs(a[j]-a[i]) instead