• + 0 comments

    I aimed to make the code traverse both lists only once, and this was the result. Any suggestions for improvement?

    def climbingLeaderboard(ranked, player):
        ranked = sorted(set(ranked), reverse=True)
        player = sorted(player, reverse=True)
        player_ranks = []
        
        i = 0
        
        for p in player:
            while i <= len(ranked):
                if i == len(ranked):
                    player_ranks.append(i + 1)
                    break
                elif p >= ranked[i]:
                    player_ranks.append(i + 1)
                    break
                i += 1
    
        return sorted(player_ranks, reverse=True)