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.
Climbing the Leaderboard
Climbing the Leaderboard
Sort by
recency
|
2331 Discussions
|
Please Login in order to post a comment
Python, O(n+m)
First the list is converted to a set and then back to a list to remove all dupes. Then loops through each element of players, deprecating the ranking and deleting every value of ranked smaller than the player value. The while loop is only ever entered len(ranked) times.
C# Code
I guess O(n²) doesn't work on C#. Time limit exceed error. Perfect logic though I think.
Python solution
def climbingLeaderboard(ranked, player): ranked = sorted(set(ranked),reverse=True) index = len(ranked) - 1 output = [] for i in player: while index >= 0 and i >= ranked[index]: index -= 1 output.append(index+2)
return output