Created
August 10, 2017 09:28
-
-
Save technoknol/35d1a5095afeb26f63c75fb04fed33e2 to your computer and use it in GitHub Desktop.
[Solved] Hacker Rank - Birthday Cake Candles
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 birthdayCakeCandles($n, $ar) { | |
// Complete this function | |
$max = $ar[0]; | |
$counts = []; | |
foreach($ar as $a) { | |
if(isset($counts[$a])) { | |
$counts[$a]++; | |
}else { | |
$counts[$a] = 1; | |
} | |
if($a > $max) { | |
$max = $a; | |
} | |
} | |
return $counts[$max]; | |
} | |
fscanf($handle, "%i",$n); | |
$ar_temp = fgets($handle); | |
$ar = explode(" ",$ar_temp); | |
$ar = array_map('intval', $ar); | |
$result = birthdayCakeCandles($n, $ar); | |
echo $result . "\n"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment