@above: but this may lead to overflow of the integer as you don't know what
is "n".
if the value of n is large then you can;t do this....
On Thu, Jul 29, 2010 at 3:26 AM, Minotauraus <[email protected]> wrote:
> If numbers are consecutive you can do better. Calculate (n-1)(n-2)/2 -
> sum of all elements in the array.
>
> That'll require one less loop compared to XORing twice.
>
> -Minotauraus.
>
> On Jul 28, 8:51 am, Apoorve Mohan <[email protected]> wrote:
> > Solution :
> >
> > 1. Find Xor of numbers from 1 to n-1.
> >
> > 2. Find Xor of the numbers present in the array.
> >
> > 3. Xor the results from step 1 and 2 you will get the repeated number.
> >
> > On Wed, Jul 28, 2010 at 8:46 PM, akshay <[email protected]>
> wrote:
> > > An array of unsorted numbers n is given with one no.repeated once ie
> > > n-1 distinct nos to find duplicate no. in o(n) complexity
> >
> > > --
> > > 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]<algogeeks%[email protected]>
> <algogeeks%2bunsubscr...@googlegroups.com>
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/algogeeks?hl=en.
> >
> > --
> > regards
> >
> > Apoorve Mohan
>
> --
> 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]<algogeeks%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
>
--
regards
Apoorve Mohan
--
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.