Skip to content

Instantly share code, notes, and snippets.

@flymio
Created October 1, 2018 17:05
Show Gist options
  • Save flymio/ab6e8ec5e6bea073fa826fd0344524d7 to your computer and use it in GitHub Desktop.
Save flymio/ab6e8ec5e6bea073fa826fd0344524d7 to your computer and use it in GitHub Desktop.
<?php
// Complete the birthdayCakeCandles function below.
function birthdayCakeCandles($ar) {
$maxHeight = max($ar); $cnt=0;
foreach($ar as $candle){
if($candle == $maxHeight){
$cnt++;
}
}
return $cnt;
}
$fptr = fopen(getenv("OUTPUT_PATH"), "w");
$stdin = fopen("php://stdin", "r");
fscanf($stdin, "%d\n", $ar_count);
fscanf($stdin, "%[^\n]", $ar_temp);
$ar = array_map('intval', preg_split('/ /', $ar_temp, -1, PREG_SPLIT_NO_EMPTY));
$result = birthdayCakeCandles($ar);
fwrite($fptr, $result . "\n");
fclose($stdin);
fclose($fptr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment