|
| 1 | +# Breaking The Record |
1 | 2 |
|
2 | | -# Breaking The Record (Hackerrank) |
| 3 | +**Problem from HackerRank** |
3 | 4 |
|
4 | | -## Problem Statement |
5 | 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 | 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 | | - |
| 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. |
9 | 8 |
|
| 9 | + Count |
| 10 | + Game Score Minimum Maximum Min Max |
| 11 | + 0 12 12 12 0 0 |
| 12 | + 1 24 12 24 0 1 |
| 13 | + 2 10 10 24 1 1 |
| 14 | + 3 24 10 24 1 1 |
10 | 15 |
|
11 | 16 | 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 | 17 |
|
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. |
| 18 | +**Function Description** |
| 19 | + |
| 20 | +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 | 21 |
|
16 | 22 | breakingRecords has the following parameter(s):
|
17 | 23 |
|
18 | 24 | scores: an array of integers
|
19 | 25 |
|
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.... |
| 26 | +**Input Format** |
| 27 | + |
| 28 | +The first line contains an integer `n` , the number of games. |
| 29 | +The second line contains `n` space-separated integers describing the respective values of score<sub>0</sub>, score<sub>1</sub>.... |
| 30 | + |
| 31 | +_Output Format_ |
23 | 32 |
|
24 | | -## Output Format |
25 | 33 | Print two space-seperated integers describing the respective numbers of times the best (highest) score increased and the worst (lowest) score decreased.
|
| 34 | + |
| 35 | +**Constraints** |
| 36 | + |
| 37 | +- 1 <= `n` <= 1000 |
| 38 | +- 0 <= `scores[i]` <= 10<sup>8</sup> |
| 39 | + |
| 40 | +## Examples |
| 41 | + |
| 42 | +### Example 1 |
| 43 | + |
| 44 | +**Input:** |
| 45 | + |
| 46 | +```java |
| 47 | +9 |
| 48 | +10 5 20 20 4 5 2 25 1 |
| 49 | +``` |
| 50 | + |
| 51 | +**Output:** |
| 52 | + |
| 53 | +```java |
| 54 | +2 4 |
| 55 | +``` |
| 56 | + |
| 57 | +**Explaination:** The diagram below depicts the number of times Maria broke her best and worst records throughout the season: |
| 58 | + |
| 59 | +<img src="https://s3.amazonaws.com/hr-assets/0/1487360234-6bca5c518d-breakingbest3.png" /> |
| 60 | + |
| 61 | +She broke her best record twice (after games **2** and **7** ) and her worst record four times (after games **1**, **4**, **6**, and **8** ), so we print 2 4 as our answer. Note that she did not break her record for best score during game **3**, as her score during that game was not strictly greater than her best record at the time. |
| 62 | + |
| 63 | +### Example 2 |
| 64 | + |
| 65 | +**Input:** |
| 66 | + |
| 67 | +```java |
| 68 | +10 |
| 69 | +3 4 21 36 10 28 35 5 24 42 |
| 70 | +``` |
| 71 | + |
| 72 | +**Output:** |
| 73 | + |
| 74 | +```java |
| 75 | +4 0 |
| 76 | +``` |
| 77 | + |
| 78 | +**Explaination:** The diagram below depicts the number of times Maria broke her best and worst records throughout the season: |
| 79 | +<img src="https://s3.amazonaws.com/hr-assets/0/1487360375-aee4388234-breakingbest5.png" /> |
| 80 | + |
| 81 | +She broke her best record four times (after games **1**, **2**, **3**, and **9**) and her worst record zero times (no score during the season was lower than the one she earned during her first game), so we print 4 0 as our answer. |
0 commit comments