I am given two arrays (can contain duplicates and of same length) containing positive integers. I have to find the maximum number of pairs that have absolute difference less than equal to a particular value (given) when numbers can be used only once from both the arrays.
For example:
arr1 = {1,2,3,4}
arr2 = {8,9,10,11}
diff = 5
Then, possible pairs are (3,8), (4,8). That is, only two such possible pairs are there.
Output should be 2.
Also, I can think of an algo for this in O(n^2). But, I need something better. I thought of hash maps (won't work because arrays contain duplicates), thought of sorting the arrays in descending and ascending order, wasn't really able to move forward from there.