Same score, same rank
Write code · Medium · §8.2 Writing binary search yourself
scores holds the scores of the people on this week's activity leaderboard, from the highest score down. A person's rank is the number of people with a higher score, plus 1. So people with the same score have the same rank.
asks holds the scores of the people who asked for their rank, and everyone who asked is on the leaderboard. Complete the function solution, which returns a list of the ranks in the order the people asked.
Function
solution(scores, asks)
Constraints
- The length of
scoresis from 1 to 700,000, and its elements are in descending order. - Each element of
scoresis an integer from 0 to 1,000,000,000. - The length of
asksis from 1 to 10,000, and every element ofasksis a number inscores.
Examples
| scores | asks | result |
|---|---|---|
[95, 90, 90, 72, 60] | [72, 95] | [4, 1] |
[85, 70, 70, 70, 56, 47, 40] | [56, 85] | [5, 1] |
Starter code
def solution(scores, asks):
answer = []
return answerSolve this problem in your browser
Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.