Lets say I have two arrays A and B
A = {1,2,3}
B = {12,11,67}
and have max sum value S = 10
How 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.
Set<Pair<Integer, Integer>>to store the pairs without repetitions.S=13, with pairs (1,11), (1,12) and (2,11)?