[algogeeks] Re: How to find two missing numbers from an unsorted continuous natural numbers array [only use O(1) space and O(n) time]

2010-08-20 Thread rahul patil
do we know the range of nos in array? is it possible that negative nos are in array? On Aug 12, 6:50 pm, Dave dave_and_da...@juno.com wrote: @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

[algogeeks] Re: How to find two missing numbers from an unsorted continuous natural numbers array [only use O(1) space and O(n) time]

2010-08-12 Thread Dave
@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