title: Find the smallest positive integer that does not occur in an array
body: <p>I am trying out the following <a href="https://app.codility.com/programmers/lessons/4-counting_elements/missing_integer/" rel="nofollow noreferrer">codility.com exercise</a> to improve my skills online, I was presented with the following problem.</p>
  <blockquote>
  <p>This is a demo task.</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.<br />
  Given A = [1, 2, 3], the function should return 4.<br />
  Given A = [-1, -3], the function should return 1.</p>
  <p>Write an <strong>efficient</strong> algorithm for the following assumptions:<br />
  • N is an
  integer within the range [1..100,000);<br />
  • each element of array A is an
  integer within the range (-1,000,000..1,000,000).</p>
  <p>Copyright 2009– by Codility Limited</p>
  </blockquote>
  <p><a href="https://i.stack.imgur.com/y8nf8.png" rel="nofollow noreferrer">rendered description</a></p>
  <p>I solved it using the following solution:</p>
  <pre><code>&lt;?php
  
  class Solution {
      public function($A) {
          $posInts = [1, 2, 3, 4, 5, 6, 7, 8, 9];
          $diffs = array_diff($postInts, $A);
          $smallestPosInt = min($diffs);
          return $smallestPosInt;
      }
  }
  </code></pre>
  <p>However upon submitting I got the following score:
  <a href="https://i.stack.imgur.com/D7dj4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D7dj4.png" alt="enter image description here" /></a></p>
  <p>Now I am very unsure of what I did wrong here or how I can rewrite the code with a better algorithm.</p>