728x90
반응형
문제 : 해커랭크 - Climbing the Leaderboard
난이도: midium
언어 : C++
https://www.hackerrank.com/challenges/climbing-the-leaderboard/problem
// Complete the climbingLeaderboard function below.
vector<int> climbingLeaderboard(vector<int> scores, vector<int> alice) {
vector<int> aliceRank ;
set<int> scoreSet;
for(auto iter = scores.begin();iter!=scores.end(); iter++)
{
scoreSet.insert(*iter);
}
int rank = 1;
int idx = 1;
int prevScore = *(scoreSet.rbegin());
auto iter2 = ++(scoreSet.rbegin());
for(auto iter = alice.rbegin();iter!=alice.rend();iter++)
{
int aliceScore = *iter;
rank = idx;
for(; iter2 != scoreSet.rend();iter2++)
{
if(prevScore<=aliceScore)
{
break;
}
prevScore = *iter2;
rank++;
idx++;
}
if(prevScore > aliceScore )
rank++;
aliceRank.push_back(rank);
}
reverse(aliceRank.begin(),aliceRank.end());
return aliceRank;
}
728x90
반응형
'개발 > 코딩' 카테고리의 다른 글
해커랭크(HackerRank) - CamelCase / C++ (0) | 2020.06.30 |
---|---|
해커랭크(HackerRank) - Drawing Book / C++ (0) | 2020.06.30 |
해커랭크(HackerRank) - Bon Appétit / C++ (0) | 2020.06.26 |
해커랭크(HackerRank) - Insert a Node at the Tail of a Linked List / C++ (0) | 2020.02.13 |
해커랭크(HackerRank) - Left Rotation / C++ (0) | 2020.02.11 |
댓글