given 3 sorted arrays (A,B,C) each of size n;
and an integer D;
you have to find number of tuples (i,j,k)
such that:-
|A[i]-B[j]|<=D
|B[j]-C[k]|<=D
|A[i]-C[k]|<=D
provided time complexity of N2logN
but interviewer told that O(N),O(NlogN) solutions were also possible
PS : duplicates are possible
Edit : yes i could figure out the solution after the interview:-
either put all the points in a common array and sort them, then for each element find the number of triplets possible in range [element,element+d]-> o(n)
or find all triplets such that A[i]<=B[j]and A[i]<c[k], B[j]<A[i] &&B [j]<c[k] , C[k}<=A[i]&& C[k]<B[j]. finally check for triplets where A[i]=B[j]=C[k]. this could be done via sliding window O(N).
unfortunately i could not figure this out in the interview . maybe i was too nervous :-(


