Lets say I have two arrays A and B A = {1,2,3}B = {12,11,67}and have max sum value S = 10How many maximum number of unique pairs can be formed between the two arrays who's sum is less than or equal to S. For e.g., the two possible values here are [1,11] [2,12] hence the answer is 2. If there are none, the answer is 0. My solution was to sort both the arrays and then go do  if((Math.abs(A[i]-B[i]))<=S)                 {                 ans++;             }Although it works for this case, clearly this is incorrect. 
Find the maximum number of pairs of numbers that are in a range, between two arrays
java;algorithms;array