| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | |||||
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
| 31 |
- 파이팅
- deque
- 12865
- 1302
- REST API
- 백준
- 올바른 괄호
- 프로그래머스
- 1697
- Algorithm
- MVC
- BFS
- 2941
- python #7490 #백준 #알고리즘 #BFS
- Heap
- 라이징프로그래머2 #Android #안드로이드 #Quitter #MakeUs
- 알고리즘
- CS
- level3
- 안드로이드
- 최소힙
- 백준 #알고리즘 # Algorithm #파이썬
- AOS
- 1766
- 디자인패턴
- 1715
- Python
- 해커랭크
- 파이썬
- 1759
Liam 일지
Hacker Rank (Climbing the Leaderboard) 본문
문제
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.
def climbingLeaderboard(ranked, player):
result = []
cnt = 0
duplicate_rank = set(ranked)
sub = list(duplicate_rank)
sub = sorted(sub, reverse=True)
for i in range(len(player)):
for j in range(len(sub)):
if player[i] >= sub[j]:
result.append(j + 1)
cnt += 1
break
elif player[i] < sub[-1]:
result.append(len(sub) + 1)
cnt += 1
break
return result
다음과 같이 중복된 점수를 제거하기위해 set로 표현한 뒤 이중포문을 이용하여 구현을 해보았지만 테스트케이스의 run time error가 나와서 player의 점수가 오름차순으로 나타낸 점을 포인트로 인덱스를 통한 해결방법을 생각해보았다.
def climbingLeaderboard(ranked, player):
cnt = 0
duplicate_rank = set(ranked)
sub = list(duplicate_rank)
sub = sorted(sub, reverse=True)
idx = len(sub)
for i in player:
while sub[idx - 1] <= i and idx > 0:
idx -= 1
if(idx<0):
result.append(1)
continue
result.append(idx+1)
www.hackerrank.com/challenges/climbing-the-leaderboard/problem
Climbing the Leaderboard | HackerRank
Help Alice track her progress toward the top of the leaderboard!
www.hackerrank.com
'Algorithm(백준)' 카테고리의 다른 글
| HackerRank (0) | 2021.05.01 |
|---|---|
| 백준 2644번 촌수계산 (0) | 2021.04.30 |
| 배열 평탄화 (0) | 2021.04.29 |
| 백준 2941번 크로아티아 알파벳 (0) | 2021.04.28 |
| 백준 1325번 효율적인 해킹 (0) | 2021.04.24 |