Solution of 'Breaking the Records' (HackerRank)

Hi all!

Here's my solution to 'Breaking the Records' of HackerRank.

#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
using namespace std;

vector<int> breakingRecords(vector<int> scores) {
    int M=scores[0],m=scores[0],M_cnt=0,m_cnt=0;
    vector<int> temp;
    for(int i=0;i<scores.size();i++){
        if(scores[i]<m){
            m=scores[i];
            m_cnt++;
        }
        if(scores[i]>M){
            M=scores[i];
            M_cnt++;
        }
    }
    temp.pb(M_cnt);
    temp.pb(m_cnt);
    return temp;
}

int32_t main()
{
    int n;
    cin>>n;
    vector<int> scores;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        scores.pb(x);
    }
    vector<int> res= breakingRecords(scores);
    for(int i=0;i<res.size();i++) cout<<res[i]<<' ';
    return 0;
}

Comments

Popular posts from this blog

Solution of 'The Two Dishes' (Codechef)

Solution of 'Tom Riddle's Diary' (Codeforces)

Solution of 'Less or Equal' (Codeforces)