I think we are using hash , which is like extra spaace , but as per the
question , O(s) = 1.

Thx,
--Gopi

On Fri, Aug 19, 2011 at 2:15 AM, icy` <vipe...@gmail.com> wrote:

> #!/usr/bin/ruby -w
> #array of unsorted positive integers
> # find the [only] one that is duplicated
>
> arr= [97,2,54,26,67,12,1,19,44,4,29,36,67,14,93,22,39,89]
> h = Hash.new(0)
>
> arr.each {|n|
>        h[n]+=1
>        (puts n; break) if h[n]==2
> }
>
> #output
> #67
>
> I hope this meets the requirements ;P
>
> On Aug 18, 3:15 pm, "*$*" <gopi.komand...@gmail.com> wrote:
> > How to find duplicate element (only one element is repeated) from an
> array
> > of unsorted positive integers..
> > time complexity .. O(n)
> > space .. o(1).
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@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.
>
>


-- 
Thx,
--Gopi

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@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.

Reply via email to