title: PHP code to find first covering prefix of an array
body: <p>A non-empty zero-indexed array A consisting of N integers is given. The first covering prefix of array A is the smallest integer P such that $0 \leq P &lt; N$ and such that every value that occurs in array A also occurs in sequence $A[0], A[1], \ldots, A[P]$.</p>
  
  <p>For example, the first covering prefix of array A such that</p>
  
  <pre><code>A[0]=2   A[1]=2   A[2]=1   A[3]=0   A[4]=1
  </code></pre>
  
  <p>is 3, because sequence <code>A[0], A[1], A[2], A[3]</code> equal to <code>2, 2, 1, 0</code> contains all values that occur in array A. </p>
  
  <p>Write a function </p>
  
  <pre><code>int ps(int[] A);
  </code></pre>
  
  <p>that given a zero-indexed non-empty array A consisting of N integers returns the first covering prefix of A. Assume that <code>$N &lt;= 1,000,000$</code>. Assume that each element in the array is an integer in range <code>[0..N-1]</code>.</p>
  
  <p>For example, given array A such that <code>A[0]=2   A[1]=2   A[2]=1   A[3]=0   A[4]=1</code></p>
  
  <p>the function should return 3, as explained in the example above.</p>