Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

HackerEarth Scoreboard queries problem solution

YASH PAL, 31 July 202413 February 2026
In this HackerEarth Scoreboard queries problem solution In a tournament, there are (N + 1) players, N players have already played and their scores are denoted by an array A. Here, A1 is the score of the first player, A2 of the second, …, An of the Nth player.
 
Now, the organizers decide the ranks according to the following rules:
 
The player x scored more than player y, player x gets a better rank.
 
In the case of a tie, the player with lower indices gets a better rank.
 
Now, it is the turn of the (N + 1)th player to play. Before playing, he wants to know the number of ranks that he can secure so that he can decide his strategy.
 
Now, the jury has some scoreboard updates. Therefore, your task is to tell the jury after every update the number of distinct possible ranks that he can get.
 
 
HackerEarth Scoreboard queries problem solution

 

 

HackerEarth Scoreboard queries problem solutions.

#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
#define endl "n"
#define test ll txtc; cin>>txtc; while(txtc--)
typedef long long int ll;
typedef long double ld;
int main() {
FIO;
test
{
ll n,q,x,l,r; cin>>n>>q;
set<ll>s;
map<ll,ll>mp;
vector<ll>a(n);
for(int i=0;i<n;i++){
cin>>a[i];
s.insert(a[i]);
mp[a[i]]++;
}
while(q--){
cin>>l>>r;
l--;
mp[a[l]]--;
if(mp[a[l]]==0){
s.erase(s.find(a[l]));
}
mp[r]++;
s.insert(r);
a[l]=r;
cout<<(ll)s.size()+1ll<<endl;
}

}
return 0;
}
 

Second solution

t = int(input())
while t > 0:
t -= 1
n, q = map(int, input().split())
have = dict()
scores = list(map(int, input().split()))
for score in scores:
have[score] = have.get(score, 0) + 1
while q > 0:
q -= 1
i, nw = map(int, input().split())
i -= 1
have[scores[i]] -= 1
if have[scores[i]] == 0:
have.pop(scores[i])
scores[i] = nw
have[scores[i]] = have.get(scores[i], 0) + 1
print(len(have) + 1)
 
 
coding problems solutions HackerEarth HackerEarth

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes