@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 <rutura...@gmail.com> wrote: > On Oct 27, 8:21 am, "MOHIT ...." <mohit...@gmail.com> 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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.