• + 0 comments

    This short Python solution takes advantage of the fact that the player scores are listed in ascending order. We first make a sorted list of unique leader scores, then for each player score, removing the elements which are smaller than the player score, the length of the remaining leader scores plus one is thus the rank of the player score. The process is continued with the shorten leader scores list, thus saves a lot of steps.

    def climbingLeaderboard(ranked, player):
        ranks = []
        new_ranked = list(set(ranked.copy()))
        new_ranked = sorted(new_ranked)
        for score in player:
            while new_ranked and score >= new_ranked[0]:
                new_ranked.pop(0)
            ranks.append(len(new_ranked) + 1)        
        return ranks