Find out all the elements in A and B such that the A[i]-B[j]=C[k]

You have been given three arrays A,B and C.
You have to find out all the elements in A and B such that the A[i]-B[j]=C[k]

 

A:

1. Put all the elements of array C in a HashTable - O(n) time and O(n) space
2. Calculate all the possible differences of A[i] and B[j]. and check whether diff is present in HT or not. O(n^2) time and O(1) space

posted @ 2012-05-21 22:49  百分百好牛  阅读(209)  评论(0编辑  收藏  举报