forked from ansh-ptel/HackerRank-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBreaking_the_records.java
67 lines (49 loc) · 1.5 KB
/
Breaking_the_records.java
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
import java.util.regex.*;
class Solution {
/*
* Complete the breakingRecords function below.
*/
static int[] breakingRecords(int[] s) {
int highest, lowest;
highest = lowest = s[0];
int[] result = new int[2];
for (int s_i = 1; s_i < s.length; s_i++)
{
if (s[s_i] > highest)
{
highest = s[s_i];
++result[0];
}
else if (s[s_i] < lowest)
{
lowest = s[s_i];
++result[1];
}
}
return result;
}
private static final Scanner scan = new Scanner(System.in);
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
int n = Integer.parseInt(scan.nextLine().trim());
int[] score = new int[n];
String[] scoreItems = scan.nextLine().split(" ");
for (int scoreItr = 0; scoreItr < n; scoreItr++) {
int scoreItem = Integer.parseInt(scoreItems[scoreItr].trim());
score[scoreItr] = scoreItem;
}
int[] result = breakingRecords(score);
for (int resultItr = 0; resultItr < result.length; resultItr++) {
bw.write(String.valueOf(result[resultItr]));
if (resultItr != result.length - 1) {
bw.write(" ");
}
}
bw.newLine();
bw.close();
}
}