Skip to content
Programming101
Programming101

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programming101

Learn everything about programming

HackerRank Breaking the Records problem solution

YASH PAL, 31 July 20249 August 2024

In this Breaking the Records problem you have Given the scores for a season, determine the number of times Maria breaks her records for most and least points scored during the season.

Hackerrank breaking the records solution
Hackerrank breaking the records solution

Problem solution in Python programming.

def solution(arr):
    lo = arr[0]
    hi = arr[0]
    lob = 0
    hib = 0
    for i in range(1,len(arr)):
        if arr[i] < lo:
            lob += 1
            lo = arr[i]
        if arr[i] > hi:
            hib += 1
            hi = arr[i]
    return [hib, lob]

if __name__ == "__main__":
    size = int(input())
    arr = [int(t) for t in input().strip().split()]
    ans = solution(arr)
    print(str(ans)[1:-1].replace(",",""))

Problem solution in Java Programming.

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = in.nextInt();
        int min = a[0];
        int max = a[0];
        int res1 = 0, res2 =0;
        for (int i = 1; i < n; i++) {
            if (a[i] > max) {
                res1++;
                max = a[i];
            }
            if (a[i] < min) {
                res2++;
                min = a[i];
            }
        }
        System.out.println(res1 + " "+ res2);
    }
}

 

Problem solution in C++ programming.

#include <cstdio>
#include <iostream>
#include <ctime>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <set>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <bitset>
#include <fstream>
#include <deque>
#include <stack>
#include <climits>
#include <string>
#include <queue>
#include <memory.h>
#include <map>
#include <unordered_map>

#define ll long long
#define ld double
#define pii pair <ll, ll>
#define mp make_pair

using namespace std;

int main() {
	int n;

	cin >> n;

	int a = (int)1e9;
	int b = -1000;

	int s = 0, r = 0;

	for (int i = 0; i < n; i++) {
		int x;

		scanf("%d", &x);

		if (x < a) {
			r++;
			a = x;
		}

		if (x > b) {
			s++;
			b = x;
		}
	}

	cout << s - 1 << ' ' << r - 1 << endl;

	return 0;
}

 

Problem solution in C programming.

#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; 
    scanf("%d",&n);
    int min;
    int countmin = 0;
    int max;
    int countmax = 0;
    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 (int i = 1; i < n; i++){
        if (score[i] > max){
            countmax++;
            max = score[i];
        }
        if (score[i] < min){
            countmin++;
            min = score[i];
        }
    }
    printf("%d %d", countmax, countmin);
    return 0;
}

 

Problem solution in JavaScript programming.

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 main() {
    var n = parseInt(readLine());
    score = readLine().split(' ');
    score = score.map(Number);
    let min = score[0]; 
    let max = score[0];
    let min_decreased = 0;
    let max_increased = 0;
    
    // your code goes here
    for (let i = 1; i < n; i++) {
        if (score[i] < min) {
            min = score[i];
            min_decreased++
        }
        if (score[i] > max) {
            max = score[i];
            max_increased++;
        }
    }
    console.log(max_increased + ' ' + min_decreased);
}

 

algorithm coding problems

Post navigation

Previous post
Next post
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
  • Hackerrank Day 6 Lets Review 30 days of code solution
  • Hackerrank Day 14 scope 30 days of code solution
©2025 Programming101 | WordPress Theme by SuperbThemes