Re: [algogeeks] Is this code correct?

2011-06-12 Thread Piyush Sinha
Do u want to output all the pairs or just 2 integers?? On 6/12/11, p2pnode wrote: > Problem: > > Given an integer 'k' and an sorted array A (can consist of both +ve/- > ve nos), output 2 integers from A such that a-b=k. > PS: > nlogn solution would be to check for the occurence of k-a[i] (using >

[algogeeks] Is this code correct?

2011-06-12 Thread p2pnode
Problem: Given an integer 'k' and an sorted array A (can consist of both +ve/- ve nos), output 2 integers from A such that a-b=k. PS: nlogn solution would be to check for the occurence of k-a[i] (using binary search) when you encounter a[i]. methods like hash consume space. Is an O(n) solution wi