• + 0 comments

    Remove duplicates in ranked array and then sort the player array in descending order. iterate through ranked array until find the point which is less than the player's, and append the (index + 1) into the result array. Finally sort the result in descending order.

    def climbingLeaderboard(ranked, player):
        # Write your code here
        player.sort(reverse = True)
        res = []
        index = 0
        ranked = list(dict.fromkeys(ranked))
        for i in player:
            while index < len(ranked) and ranked[index] > i:
                index += 1
            if index >= len(ranked):
                index = len(ranked)
                res.append(index + 1)
                continue
            res.append(index + 1)
        res.reverse()
        return res