runtime
341 / 500
question 341 Algorithms & Complexity · easy

Rank on a leaderboard

A quiz app keeps every player's score in a sorted list. After each game it shows the player their rank: 1 plus the number of players who scored more, so equal scores share a rank. The list holds hundreds of thousands of scores, so answer with a binary search, not a scan.

Functionrank_of(scores, score)
scoresevery player's score, sorted from lowest to highest (scores may repeat)
Returns1 + the number of scores strictly greater than score; score doesn't have to be in the list
Constraintread at most 40 of 100,000 scores
Examples
callrank_of([52, 61, 61, 70, 88], 61)returns3
callrank_of([52, 61, 61, 70, 88], 88)returns1
callrank_of([52, 61, 61, 70, 88], 50)returns6

Loading your progress…

Rank on a leaderboard — Python practice · Runtime