Last active
March 13, 2016 00:11
-
-
Save gpfiel/cc406e976b09a8728673 to your computer and use it in GitHub Desktop.
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 | |
function solution($X, $A) { | |
foreach ($A as $key => $value) { | |
$part1 = array_slice($A, 0, $key); | |
$part2 = array_slice($A, $key, count($A) - 1); | |
$arrayPart1Indexes = array(); | |
$arrayPart2Indexes = array(); | |
foreach ($part1 as $part1key => $part1Value) { | |
if ($part1Value === $X) { | |
$arrayPart1Indexes[] = $part1key; | |
} | |
} | |
foreach ($part2 as $part2key => $part2Value) { | |
if ($part2Value !== $X) { | |
$arrayPart2Indexes[] = $part2key; | |
} | |
} | |
if (count($arrayPart1Indexes) === count($arrayPart2Indexes)) { | |
return $key; | |
} | |
} | |
return 0; //forget to put this on solution | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment