hi this problem is already solver previously.
check for "Re: Finding Repeated and Missing Numbers"

if X is the missing number and Y is the repeating number.

then let S(N) = n*(n+1)/2
sum of all the numbers provided be Sn

ler S(N2) = n*(n+1)*(2*n+1)/6
sum of square of all the numbers provided be Sn2

now if
D1 = S(N) - Sn
and D2 = S(N2) - Sn2

then X = (D2 + (D1*D1)) / (2*D1)
and Y = (D2 - (D1*D1)) / (2*D1)

So its a order O(n) solution.

regards
swadhin

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