@mohit,ruturaj
We dont need to know the range only if there are +ve no's.
and then also we need only m/2 space.
if(a[i]>m)
skip
else
if(a[i]>m/2)
if(hash[m-a[i]]==1))
return true;
else
hash[m-a[i]]++;
else
if(hash[a[i]]==1))
return true;
else
hash[a[i]]++;
but we need to know the range if there are -ve numbers as well.
we need hashtable
On Nov 12, 3:29 am, Ruturaj <[email protected]> wrote:
> On Oct 27, 8:21 am, "MOHIT ...." <[email protected]> wrote:> @ruturaj : but
> for that hash table you have to know range??
>
> Nope we dont need the range.
>
> #include<map>
>
> map <int, int> hash;
>
> for(int i=0;i<n;i++)
> if(hash[m-a[i]] > 0)count++;hash[a[i]]++;
>
> does the trick.
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.