HackerRank Breaking the Records Problem Solution in C
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>
int main(){
int n;
int min, max, minc=0, maxc=0, i;
scanf("%d",&n);
int *score = malloc(sizeof(int) * n);
for(int score_i = 0; score_i < n; score_i++){
scanf("%d",&score[score_i]);
}
min=max=score[0];
for(i=1;i<n;i++) {
if(score[i]<min) {
minc++;
min=score[i];
}
if(score[i]>max) {
maxc++;
max=score[i];
}
}
printf("%d %d",maxc,minc);
return 0;
}HackerRank Breaking the Records Problem Solution in JavaScript
process.stdin.resume();
process.stdin.setEncoding('ascii');
var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;
process.stdin.on('data', function (data) {
input_stdin += data;
});
process.stdin.on('end', function () {
input_stdin_array = input_stdin.split("\n");
main();
});
function readLine() {
return input_stdin_array[input_currentline++];
}
/////////////// ignore above this line ////////////////////
function getRecord(s){
let min = s[0]
let max = s[0]
let numberOfTimesHighScore = 0
let numberOfTimesLowScore = 0
s.slice(1).forEach(score => {
if (score > max) {
numberOfTimesHighScore++
max = score
} else if (score < min) {
numberOfTimesLowScore++
min = score
}
})
return [numberOfTimesHighScore, numberOfTimesLowScore]
}
function main() {
var n = parseInt(readLine());
s = readLine().split(' ');
s = s.map(Number);
var result = getRecord(s);
console.log(result.join(" "));
}HackerRank Breaking the Records Problem Solution in Python
#!/bin/python3
import sys
n = int(input())
score = list(map(int, input().strip().split(' ')))
# your code goes here
h = score[0]
hh = 0
l = score[0]
ll = 0
for i in range(n-1):
if l > score[(i+1)]:
hh += 1
l = score[(i+1)]
elif h < score[(i+1)]:
ll +=1
h = score[(i+1)]
print(ll,hh)
0 Comments