Skip to content

Instantly share code, notes, and snippets.

@davidon
Created November 15, 2018 05:45
Show Gist options
  • Save davidon/4c2593fe76ef7d9f02d177dd76382e91 to your computer and use it in GitHub Desktop.
Save davidon/4c2593fe76ef7d9f02d177dd76382e91 to your computer and use it in GitHub Desktop.
find first positive number which is not in an numerical array
<?php
// you can write to stdout for debugging purposes, e.g.
// print "this is a debug message\n";
function solution($A) {
// write your code in PHP7.0
$arr_checker = range(1, 100000);
$A = array_unique($A, SORT_NUMERIC );
sort($A);
$A = array_intersect($A, $arr_checker);
$A = array_values($A);
$A = array_diff($arr_checker, $A);
return reset($A);
}
print "testing....\n";
$A = [-1,-8, 1, 3, 6, 99999, 4, 1, 2];
$result = solution($A);
print "array:" . print_r($A, true). "\nresult: $result\n\n";
@davidon
Copy link
Author

davidon commented Nov 15, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment