I think your solution will work if the repeated number is a power of 2. The
problem states that the repeated number is repeated 2, 4, 8, 16 times.

for ex: consider 3,4,3
3 is repeated two times. your algo will return i when i=4

So i feel this is not the correct solution

--------------------
Regards
Nikhil Jindal
Student
Department of Computer Engineering
Delhi College of Engineering(DCE)
Delhi

On Mon, Aug 17, 2009 at 5:32 AM, Shyam <[email protected]> wrote:

>
> I think I could do it in O(n) .
>
> var bits=0
> var @array
>
> for each i in array
>    if (bits & i)!=0
>          return i
>    else
>          bits=bits | i;
>    end if
> end for
>
> I just use the pattern for powers of two
>
> let array be 2,4,2
>
> so first
> bits=0 i=2     so bits(000) & i(010) is 0 so bits= bits | i which is
> bits=010
> next
> bits=2 i=4     so bits(010) & i(100) is 0 so bits= bits | i which is
> bits=110
> next
> bits=6 i=2     so bits(110) & i(010) is 2 which is !=0 so we return i.
>
> I think that should be it.
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to