[해커랭크] Climbing the Leaderboard
https://www.hackerrank.com/challenges/climbing-the-leaderboard/problem?isFullScreen=true
Climbing the Leaderboard | HackerRank
Help Alice track her progress toward the top of the leaderboard!
www.hackerrank.com
An arcade game player wants to climb to the top of the leaderboard and track their ranking. The game uses Dense Ranking, so its leaderboard works like this:
- The player with the highest score is ranked number on the leaderboard.
- Players who have equal scores receive the same ranking number, and the next player(s) receive the immediately following ranking number.
Example
The ranked players will have ranks , , , and , respectively. If the player's scores are , and , their rankings after each game are , and . Return .
Function Description
Complete the climbingLeaderboard function in the editor below.
climbingLeaderboard has the following parameter(s):
- int ranked[n]: the leaderboard scores
- int player[m]: the player's scores
Returns
- int[m]: the player's rank after each new score
Input Format
The first line contains an integer , the number of players on the leaderboard.
The next line contains space-separated integers , the leaderboard scores in decreasing order.
The next line contains an integer, , the number games the player plays.
The last line contains space-separated integers , the game scores.
Constraints
- for
- for
- The existing leaderboard, , is in descending order.
- The player's scores, , are in ascending order.
Subtask
For of the maximum score:
100 100 50 40 40 20 10
4
5 25 50 120
Sample Output 1
4
2
1
Explanation 1
Alice starts playing with players already on the leaderboard, which looks like this:

After Alice finishes game , her score is and her ranking is :

After Alice finishes game , her score is and her ranking is :

After Alice finishes game , her score is and her ranking is tied with Caroline at :

After Alice finishes game , her score is and her ranking is :

100 90 90 80 75 60
5
50 65 77 90 102
Sample Output 2
5
4
2
1
풀이
코드를 보면 알다시피, 처음엔 그냥 Set에 중복없이 넣고, 정렬해서 List저장하고 index 찾으면 되겠구나 싶었다.
그 코드가 바로 climbingLeaderboardTimeout
타임아웃이 나더라
매번 정렬해주는게 문제일테고
문제상 ranked가 내림차순, palyer가 오름차순 정렬되어 input값으로 들어온다는 정보에 주목했다.
그리하여 푼 해결방법이 climbingLeaderboard 이다.
while문으로 player의 첫번째 큰 숫자값부터 하나를 꺼내서,
ranked의 가장 우측에서부터 몇등인지 체크하는 방식으로 풀어냈다.
'알고리즘 단련장 > 해커랭크' 카테고리의 다른 글
[해커랭크] Designer PDF Viewer (1) | 2025.08.14 |
---|---|
[해커랭크] The Hurdle Race (0) | 2025.08.14 |
[해커랭크] Picking Numbers (0) | 2025.08.12 |
[해커랭크] Forming a Magic Square (2) | 2025.08.11 |
[해커랭크] Stone Division (어쩐지 난이도 Hard였구나) (3) | 2025.08.11 |