Possible Duplicate:
Interview question: three arrays and O(N*N)
We have 3 sorted arrays A, B and C.
We have to find 3 numbers from each A, B and C such that a+b+c = x
One way to do that will be to pick element from A and B and use binary search to find corresponding element in C. Complexity == O(n^2 lgn)
Is there any other way to do this with preferably no extra space and complexity O(n^2) ?
I was thinking of keeping a pointer at A ...now our question reduces to finding elements from B and C such that their sum is (x-a) but got little lost in this approach .