We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Here is an annotated version of albiewalbie's solution, but in Python3 and applied within the definition of the function.
I hope this helps others with the logic!
defclimbingLeaderboard(scores,alice):# List to contain and return Alice's ranks.results=[]# Unique values from scores, since duplicate scores will have same rank (their index value).leaderboard=sorted(set(scores),reverse=True)# Use this var to track index within leaderboard later.l=len(leaderboard)# Loop through each of Alice's scoresforainalice:# If Alice's score is >= the score at the index of the end of leaderboard...# Subtract 1 from that index value (which is also the rank) to check the next score up.# If the score is less than the next score up, the index (rank) will be added to results.while(l>0)and(a>=leaderboard[l-1]):l-=1# We add 1 to the appended value to account for 0-indexing.results.append(l+1)returnresults
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Climbing the Leaderboard
You are viewing a single comment's thread. Return to all comments →
Here is an annotated version of albiewalbie's solution, but in Python3 and applied within the definition of the function.
I hope this helps others with the logic!