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.
defclimbingLeaderboard(ranked,player):# Remove duplicates and sort unique ranks in descending orderranks=[ranked[0]]forrankinranked:ifrank<ranks[-1]:ranks.append(rank)# Initialize list to store player rankingsplayer_rankings=[]# Initialize pointers for traversing ranks and playersrank_ptr=len(ranks)-1player_ptr,end=0,len(player)-1# Iterate through each player's scorewhileplayer_ptr<=end:# If there are no more ranks or the player's score is less than the current rankifrank_ptr==-1orplayer[player_ptr]<ranks[rank_ptr]:# Append the current rank position + 1 to the player rankingsplayer_rankings.append(rank_ptr+2)# Move to the next playerplayer_ptr+=1# If the player's score is greater than or equal to the current rankelse:# Move to the next rankrank_ptr-=1returnplayer_rankings
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 →