@Karthik: There was no requirement that the numbers be between 1 and
n. Only positive and one number is repeated. So 1, 9, 11, 1 also is
valid input, with expected output 1.

Dave

On Oct 20, 11:30 pm, karthik asok <karthika...@gmail.com> wrote:
> Considering sequence 1, 2, 3, 4, 4 and n = 5
> lets have missing number as X and repeated number as Y.
>
> (1*2*3*4*4)/n! = 4/5=Y/X => 5Y = 4X => Y=4X/5
>
> (sum of all numbers) + X - Y = n(n+1)/2.
> 14 + X - Y = 15
> X-4X/5=1
>
> X = 5 ---> missing value is 5.
> Y = 4 --> repeated value.
>
>
>
>
>
> On Wed, Oct 20, 2010 at 7:26 PM, Dave <dave_and_da...@juno.com> wrote:
> > @Mahesh: Let's try this on 1, 2, 3, 4, 4. Then S = 14 and X_SUM = 0.
> > But the duplicate element is 4, not (14-0) / 2 = 7.
>
> > Dave
>
> > On Oct 20, 5:49 am, Mahesh_JNU <mahesh.jnumc...@gmail.com> wrote:
> > > Just add the number of the array and let the sum is S. Its complexity is
> > > O(n).
> > > Now XOR all elements of the array and say the result is X_SUM.Its
> > complexity
> > > is  O(n).
> > > Now the duplicate element is = (S - X_SUM)/2
>
> > > On Wed, Oct 20, 2010 at 4:14 PM, Asquare <anshika.sp...@gmail.com>
> > wrote:
> > > > @Anirvana - In context to the XOR method u suggested, could u plz
> > > > explain why does it so happen.. ??
>
> > > > --
> > > > 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<algogeeks%2bunsubscr...@googlegroups­.com>
> > <algogeeks%2bunsubscr...@googlegroups­.com>
> >  > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/algogeeks?hl=en.
>
> > > --
> > >    Mahesh Giri
>
> > --
> > 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<algogeeks%2bunsubscr...@googlegroups­.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/algogeeks?hl=en.
>
> --
> Thanks & Regards,
> Karthik- Hide quoted text -
>
> - Show quoted text -

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

Reply via email to