title: Finding missing elements in an array
body: <p>Given you have an array A[1..n] of size n, it contains elements from the set {1..n}. However, two of the elements are missing, (and perhaps two of the array elements are repeated). Find the missing elements. </p>
  
  <p>Eg if n=5, A may be A[5] = {1,2,1,3,2}; and so the missing elements are {4,5}</p>
  
  <p>The approach I used was:</p>
  
  <pre><code>int flag[n] = {0};  
  int i;  
  for(i = 0; i &lt; n; i++)  {  
    flag[A[i]-1] = 1;  
   }  
  
  for(i = 0; i &lt; n; i++)  {  
   if(!flag[i]) {  
      printf("missing: %d", (i+1));  
  }  
  </code></pre>
  
  <p>the space complexity comes to O(n). I feel this is a very kiddish and inefficient code. So could you please provide a better algo with better space and time complexity. </p>