title: returns the smallest positive integer (greater than 0) that does not occur in Array
body: <p>I have the following question:-</p>
  <p>Write a function:</p>
  <pre><code>class Solution { public int solution(int[] A); }
  </code></pre>
  <p>that, given an array A of N integers, returns the smallest positive integer (greater than 0) that does not occur in A.</p>
  <p>For example, given A = [1, 3, 6, 4, 1, 2], the function should return 5.</p>
  <p>Given A = [1, 2, 3], the function should return 4.</p>
  <p>Given A = [−1, −3], the function should return 1.</p>
  <p>Write an efficient algorithm for the following assumptions:</p>
  <ul>
  <li>N is an integer within the range [1..100,000];</li>
  <li>each element of array A is an integer within the range [−1,000,000..1,000,000].</li>
  </ul>
  <p>now i tried this code:-</p>
  <pre><code>using System;
  // you can also use other imports, for example:
  // using System.Collections.Generic;
  
  // you can write to stdout for debugging purposes, e.g.
  // Console.WriteLine(&quot;this is a debug message&quot;);
  
  class Solution
  {
      public int solution(int[] A)
      {
          // write your code in C# 6.0 with .NET 4.5 (Mono)
          int n = 1;
          Array.Sort(A);
          for (int i = 1; i &lt;= 100000; i++)
          {
              for (int i2 = 0; i2 &lt;= A.Length - 1; i2++)
              {
                  if (A[i2] == i)
  
                  {
                      n = A[i2] + 1;
                      break;
                  }
  
              }
  
  
  
          }
          return n;
  
      }
  }
  </code></pre>
  <p>where my code worked well for these test data:-</p>
  <p>A = [1, 2, 3]</p>
  <p>A = [−1, −3]</p>
  <p>while failed for this one:-</p>
  <p>A = [1, 3, 6, 4, 1, 2] where it return 7 instead of 5.</p>
  <p>any advice why my code failed on the 3rd test?</p>
  <p>Thanks</p>