Skip to content

Instantly share code, notes, and snippets.

@flymio
Created January 2, 2019 14:33
Show Gist options
  • Save flymio/eea9f326de2e8bf233720d695420e3ba to your computer and use it in GitHub Desktop.
Save flymio/eea9f326de2e8bf233720d695420e3ba to your computer and use it in GitHub Desktop.
<?php
// Complete the breakingRecords function below.
function breakingRecords($scores) {
$max = $scores[0]; $min = $scores[0];
$max_count=0;
$min_count=0;
foreach($scores as $value){
if ($value>$max){
$max=$value; $max_count++;
}
if ($value<$min){
$min=$value; $min_count++;
}
}
return array($max_count, $min_count);
}
$fptr = fopen(getenv("OUTPUT_PATH"), "w");
$stdin = fopen("php://stdin", "r");
fscanf($stdin, "%d\n", $n);
fscanf($stdin, "%[^\n]", $scores_temp);
$scores = array_map('intval', preg_split('/ /', $scores_temp, -1, PREG_SPLIT_NO_EMPTY));
$result = breakingRecords($scores);
fwrite($fptr, implode(" ", $result) . "\n");
fclose($stdin);
fclose($fptr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment