
Solution in php:
function solution($X, $A) {
$tiles = array();
for ($i = 0; $i < count($A); $i++){
$j = $A[$i] - 1;
if (!isset($tiles[$j])){
$X--;
$tiles[$j] = true;
}
if (!$X){
return $i;
}
}
return -1;
}
Given “AS IS”, can be ported from other languages from solutions found on the internet, please use with care.
Please note: we think that codility.com does not give a correct assessment of your real-world programming skills. For instance, reading the below would bring more understanding why: http://codility-test-questions.blogspot.com/2013/01/my-experience-with-codility-test.html
