-
Notifications
You must be signed in to change notification settings - Fork 0
/
Breaking the Records.php
45 lines (34 loc) · 997 Bytes
/
Breaking the Records.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
/**
* @author: syed ashraf ullah
* date: 26/04/2020
* problem: https://www.hackerrank.com/challenges/breaking-best-and-worst-records/problem
*/
// Complete the breakingRecords function below.
function breakingRecords($scores) {
$highestScore = $scores[0];
$lowestScore = $scores[0];
$count = array();
$count[0] = 0;
$count[1] = 0;
foreach ($scores as $value) {
if ($value > $highestScore) {
$highestScore = $value;
$count[0]++;
}
if ($value < $lowestScore) {
$lowestScore = $value;
$count[1]++;
}
}
return $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);