given an array of integer size N.
a) find all pairs whose sum is some given value X. array is not sorted & values are distinct. in o(log n)
b) array is sorted. & values can repeat. in o(n) & space compl o(1)
a) hash table O(n) time, better idea???
b) two pointers, p1 points to start, p2 points to end, if equal to sum, p1++;p2--; else if bigger than sum, p2--; else p1++
Dec 26, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment