Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 6 hours ago.

Problem statement:

• Alice is playing an arcade game and wants to climb to the top of the leaderboard and wants to track her ranking. The game uses Dense Ranking, so its leaderboard works like this:

1. The player with the highest score is ranked number 1 on the leaderboard.

2. Players who have equal scores receive the same ranking number, and the next player(s) receive the immediately following ranking number. input:

• first line contains number of scores on leaderboard
• second line contains scores on leaderboard
• third line contains number of alice plays
• fourth line contains scores of alice

Output:

The position of alice on the leaderboard for each of his score how can I optimize the code so that I can complete it in minimum time.I am getting time complexity error for some inputs in test cases in hackerrank.

``````'''

{
int n,m,i=0,j;
cin >> n;
int score[n];
while(i<n)
{
cin >> score[i];
i++;
}
i=0;
vector<int> v;
cin >> m;
int alice[m];
for(i=0;i<n;i++)
{
if(i==0)
{
v.push_back(score[i]);
}
else if(score[i]!=score[i-1])
{
v.push_back(score[i]);
}
else
continue;
}
i=0;
while(i<m)
{
cin >> alice[i];
int p=1;
for(j=0;j<v.size();j++)
{
if(v[j]>alice[i])
{
p++;
}
else
{
break;
}

}
cout << p << endl;
i++;
}
return 0;

}

'''
``````