Skip to content

Instantly share code, notes, and snippets.

@technoknol
Created August 10, 2017 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save technoknol/35d1a5095afeb26f63c75fb04fed33e2 to your computer and use it in GitHub Desktop.
Save technoknol/35d1a5095afeb26f63c75fb04fed33e2 to your computer and use it in GitHub Desktop.
[Solved] Hacker Rank - Birthday Cake Candles
<?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