How do you do this? The values are unsorted but are of [1..n]
Example array [3,1,2,5,7,8]
. Answer: 4, 6
I saw this solution in
I have an algorithm for above problem.
Suppose
Actual Series: 1 2 3 4 5 6 a:sum=21 product= 720
Missing Number series: 1 * 3 4 * 6 b:sum=14 product= 72
a+b=21-14= 7 , ab=720/72=10
Now we need to find a-b= sqrt[(a+b)^2 -4ab]
.
If you calculate:
a-b= 3
Now
a+b=7
a-b=3
Add both equations:
2a=10, a=5
then b=7-5=2
so, 2
and 5
are missing.