title: Work out a solution for codality?
body: <p>A zero-indexed array A consisting of N different integers is given. The array contains integers in the range <code>[1..(N + 1)]</code>, which means that exactly one element is missing.</p>
  
  <p>Your goal is to find that missing element.</p>
  
  <p>Write a function:</p>
  
  <pre><code>int solution(int A[], int N); 
  </code></pre>
  
  <p>that, given a zero-indexed array <code>A</code>, returns the value of the missing element.</p>
  
  <p>For example, given array A such that:</p>
  
  <pre><code>A[0] = 2 A[1] = 3 A[2] = 1 A[3] = 5
  </code></pre>
  
  <p>the function should return <code>4</code>, as it is the missing element.</p>
  
  <p>Assume that:</p>
  
  <pre><code>N is an integer within the range [0..100,000];
  the elements of A are all distinct;
  each element of array A is an integer within the range [1..(N + 1)].
  </code></pre>
  
  <p>Complexity:</p>
  
  <pre><code>expected worst-case time complexity is O(N);
  expected worst-case space complexity is O(1), beyond input storage (not counting the storage required for input arguments).
  </code></pre>
  
  <p>It doesn't work for a case that there are two elements</p>
  
  <pre><code>int solution(vector&lt;int&gt; &amp;A) {
  
      sort(A.begin(), A.end());
      int missingIndex = 0;
  
      for (int i = 0; i &lt; A.size(); i++)
      {
          if ( i != A[i]-1)
          {
              missingIndex = i+1;
          }
  
      }
      return missingIndex;
  }
  </code></pre>