On Mon, Aug 8, 2011 at 1:07 AM, Yasir Imteyaz wrote:
> @Shuaib,
> You are right, this approach will work! :)
> But for each element 'e'
> instead of checking whether *|K-e| *exists, *you should check for either
> (e+K) or (e-K).*
>
You are right. Mistake. ;)
>
> But here the question is, will
@Shuaib,
You are right, this approach will work! :)
But for each element 'e'
instead of checking whether *|K-e| *exists, *you should check for either
(e+K) or (e-K).*
But here the question is, will the hash map really give o(1) access for such
a large record?
..and is it a good practice to creat
How about iterating over all the values and hashing them to a dict/map. And
then iterate once more, checking that for each element 'e', |K-e| exists in
the map or not. O(N)?
On Sun, Aug 7, 2011 at 10:53 PM, Yasir wrote:
> Guys,
> Let's try to find out an efficient solution for the following prob
First sort the array.Then for each element,say x ,do a binary search to find
the element y for which (y-x)=K or y=(x+K),if the elements are not distinct
then the number of pairs will be the upper_bound()-lower_bound() for y.
Complexity:O(nlogn)
On Sun, Aug 7, 2011 at 11:23 PM, Yasir wrote:
> Guy
Guys,
Let's try to find out an efficient solution for the following prob:
Given N numbers , [N<=10^5] we need to count the total pairs of
numbers that have a difference of K. [K>0 and K<1e9]
Input Format:
1st line contains N & K.
2nd line contains N numbers of the set. All the N numbers are assur