here is my code:-
tell me why it is not running
Pair of roses problem
hey @Love your logic for solving this problem is wrong you are searching if it is possible to generate a pair with given difference, but what if the minimum difference is greater than mid you never check it
for example
1
2
1 7
8
@Love One of the correct approaches would be
- store occurrence of each element in map
- iterate array and check if target - arr[i] exists it if exists compare their difference with the minimum difference and store the minimum difference
- print the solution for minimum difference
Here is the code for the same
https://ide.codingblocks.com/s/192957