I have 2 arrays A[] and B[] with n elements each , I want to calculate the difference between each element of A array to the element of B array, and output is the set of Elements with difference less than x0 (some value).
For ex : A =[1,2,3] B=[2,3,4]
I want "1-2","1-3","1-4","2-3" ...
say x0 = 2, So the output be ([1,2],[1,3],[2,3]...).
I'm using the brute force approach ,taking each element of array A and subtracting with B's element which has time complexity of O(n^2). Can anyone suggest better approach ?