positive integer but smallest from given array 2

                Never    
PHP
       
function solution($data) {
  /* pengurutan */
  sort($data);
  
  /* buat value jadi unique */
  $unique_data = array_unique($data);

  /* key di $unique_data harus di perbaiki */
  $new_data = array();
  foreach ($unique_data as $v) {
      $new_data[] = $v;
  }
  
  /* cari integer paling kecil tapi ga ada di $new_data */
  $key = 0;
  $output = NULL;
  for($i=1;$i<=100000;$i++) {
      if ($new_data[$key] == $i) {
          $key++;
          continue;
      }
      $output = $i;
      break;
      
  }
  return $output;
}

$x = [-1,-3];
echo solution($x) . "<br>";

$x = [1,2,3];
echo solution($x) . "<br>";

$x = [1,3,6,4,1,2];
echo solution($x) . "<br>";

Raw Text