I scored 100% in #php on @Codility!
https://codility.com/demo/take-sample-test/perm_missing_elem/
<?php | |
function solution($A) { | |
// write your code in PHP5.5 | |
$count = count($A); | |
if ($count < 1) return 1; | |
$end = $count + 1; | |
$ordered = range(1, $end); | |
$flip_A = array_flip($A); | |
$flip_ordered = array_flip($ordered); | |
$diff = array_diff_key($flip_ordered, $flip_A); | |
if(count($diff) == 0) return 1; | |
$key_flip = current($diff); | |
$value = $ordered[$key_flip]; | |
return $value; | |
} |
Training ticket
Session
ID: trainingWEF9F8-YEU
Time limit: 120 min.
Status: closed
Created on: 2016-01-17 03:25 UTC
Started on: 2016-01-17 03:25 UTC
Finished on: 2016-01-17 03:40 UTC
Training ticket (real finishing time)
Session
ID: trainingCSVQV7-4KF
Time limit: 120 min.
Status: closed
Created on: 2016-01-17 04:29 UTC
Started on: 2016-01-17 04:29 UTC
Finished on: 2016-01-17 04:30 UTC