@ashish. The product will overflow for even moderate n, so instead,
form the sum and the sum of the squares of the numbers. If a and b are
the missing numbers, they satisfy

a + b = n(n+1)/2 - sum of the numbers
a^2 + b^2 = n(n+1)(2n+1)/6 - sum of the squares of the numbers.

Solve by the method of substitution.

Dave

On Aug 12, 7:50 am, ashish agarwal <ashish.cooldude...@gmail.com>
wrote:
> take the sum of array and product.
> if they were present then sum will be n(n-1)/2 and product will be n!.
> make two eq of a+b and a-b with these values and get the num
>
>
>
> On Thu, Aug 12, 2010 at 5:26 AM, vijay <auvija...@gmail.com> wrote:
> > How to find two missing numbers from an unsorted continuous natural
> > numbers array [only use O(1) space and O(n) time]
>
> > --
> > 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.- 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