Created
November 15, 2018 05:45
-
-
Save davidon/4c2593fe76ef7d9f02d177dd76382e91 to your computer and use it in GitHub Desktop.
find first positive number which is not in an numerical array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For the demo task https://app.codility.com/c/run/demoZ8PATM-3DF