How To Quicken This Algorithm In Python
The problem statement is: The player with the highest score is ranked 1 number on the leaderboard. Players who have equal scores receive the same ranking number, and the next play
Solution 1:
There's no need to append Alice's scores to scores
. First make sure that scores
is sorted from high to low.
Then for each score of Alice, calculate her rank as follows:
Start with rank = 1
and iterate over the list of scores
. Add 1 to rank
every time the score you're looking at is smaller than the previous one and return the value of rank
as soon as the score you're looking at equals or is smaller than Alice's score.
EDIT
This answer assumes that only the highest score of each player is relevant.
Post a Comment for "How To Quicken This Algorithm In Python"