• + 0 comments

    Python, O(n+m)

    def climbingLeaderboard(ranked, player):
        ranks = []
        ranked = sorted(list(set(ranked)))
        currRank = len(ranked)+1
        for i in player:
            while ranked and i >= ranked[0]:
                del ranked [0]
                currRank -= 1
            ranks.append(currRank)
        return ranks
    

    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.