Skip to content

Instantly share code, notes, and snippets.

@rudwolf
Created April 3, 2018 15:26
Show Gist options
  • Save rudwolf/982ff27ccfd2abac5dc03dcc781d9192 to your computer and use it in GitHub Desktop.
Save rudwolf/982ff27ccfd2abac5dc03dcc781d9192 to your computer and use it in GitHub Desktop.
Probleminha do HackerRank
<?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