Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a615b8b

Browse files
authored
Merge pull request #70 from shikhar8434/master
Breaking The Records Problem with solution added
2 parents 16175cd + 20abf04 commit a615b8b

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import java.io.*;
2+
import java.math.*;
3+
import java.security.*;
4+
import java.text.*;
5+
import java.util.*;
6+
import java.util.concurrent.*;
7+
import java.util.regex.*;
8+
9+
public class Solution {
10+
11+
12+
static int[] breakingRecords(int[] scores) {
13+
int[] result = new int[2];
14+
int countMax=0, countMin=0 ,max = scores[0], min = scores[0];
15+
for(int i=1; i< scores.length; i++){
16+
if(scores[i] > max){ max = scores[i]; countMax++; }
17+
if(scores[i] < min){ min = scores[i]; countMin++; }
18+
}
19+
result[0] = countMax; result[1] = countMin;
20+
return result;
21+
22+
}
23+
24+
private static final Scanner scanner = new Scanner(System.in);
25+
26+
public static void main(String[] args) throws IOException {
27+
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
28+
29+
int n = scanner.nextInt();
30+
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
31+
32+
int[] scores = new int[n];
33+
34+
String[] scoresItems = scanner.nextLine().split(" ");
35+
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
36+
37+
for (int i = 0; i < n; i++) {
38+
int scoresItem = Integer.parseInt(scoresItems[i]);
39+
scores[i] = scoresItem;
40+
}
41+
42+
int[] result = breakingRecords(scores);
43+
44+
for (int i = 0; i < result.length; i++) {
45+
bufferedWriter.write(String.valueOf(result[i]));
46+
47+
if (i != result.length - 1) {
48+
bufferedWriter.write(" ");
49+
}
50+
}
51+
52+
bufferedWriter.newLine();
53+
54+
bufferedWriter.close();
55+
56+
scanner.close();
57+
}
58+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
# Breaking The Record (Hackerrank)
3+
4+
## Problem Statement
5+
Maria plays college basketball and wants to go pro. Each season she maintains a record of her play. She tabulates the number of times she breaks her season record for most points and least points in a game. Points scored in the first game establish her record for the season, and she begins counting from there.
6+
7+
For example, assume her scores for the season are represented in the array Scores= [12,24,10,24] . Scores are in the same order as the games played.
8+
9+
10+
11+
Given the scores for a season, find and print the number of times Maria breaks her records for most and least points scored during the season.
12+
13+
## Function Description
14+
Complete the breakingRecords function in the editor below. It must return an integer array containing the numbers of times she broke her records. Index 0 is for breaking most points records, and index 1 is for breaking least points records.
15+
16+
breakingRecords has the following parameter(s):
17+
18+
scores: an array of integers
19+
20+
## Input Format
21+
The first line contains n an integer , the number of games.
22+
The second line contains n space-separated integers describing the respective values of score0,score1....
23+
24+
## Output Format
25+
Print two space-seperated integers describing the respective numbers of times the best (highest) score increased and the worst (lowest) score decreased.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /