Created
April 3, 2018 15:26
-
-
Save rudwolf/982ff27ccfd2abac5dc03dcc781d9192 to your computer and use it in GitHub Desktop.
Probleminha do HackerRank
This file contains 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 | |
$handle = fopen ("php://stdin", "r"); | |
function equalizeArray($arr) { | |
$diff = 0; | |
$d = []; | |
foreach($arr as $item) { | |
@$d[$item]++; | |
} | |
$tot = count($arr); | |
$frequent = array_values($d)[0]; | |
$tofix = $tot - $frequent; | |
return $tofix; | |
} | |
fscanf($handle, "%i",$n); | |
$arr_temp = fgets($handle); | |
$arr = explode(" ",$arr_temp); | |
$arr = array_map('intval', $arr); | |
$result = equalizeArray($arr); | |
echo $result . "\n"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment