title: Find 2 missing numbers in an array of integers with two missing values
body: <p>How do you do this?  The values are unsorted but are of <code>[1..n]</code>  Example array <code>[3,1,2,5,7,8]</code>.  Answer: <code>4, 6</code></p>
  
  <p>I saw this solution in another similar <a href="/a/8532880">post</a>, but I do not understand the last step:</p>
  
  <blockquote>
    <ul>
    <li>Find the sum of the numbers S=a1+...+an.</li>
    <li>Also find the sum of squares T=a1²+...+an².</li>
    <li>You know that the sum should be S'=1+...+n=n(n+1)/2</li>
    <li>You know that the sum of squares should be T'=1²+...+n²=n(n+1)(2n+1)/6.</li>
    <li>Now set up the following system of equations x+y=S'-S, x²+y²=T'-T.</li>
    <li>Solve by writing x²+y²=(x+y)²-2xy => xy=((S'-S)²-(T'-T))/2. </li>
    <li>And now the numbers are merely the roots of the quadratic in z: z²-(S'-S)z+((S'-S)²-(T'-T))/2=0.</li>
    </ul>
  </blockquote>
  
  <p>What is the explanation for setting up that quadratic equation in the final step with z as the unknown? What's the intuition behind that being the solution to this problem?</p>