• + 0 comments

    Linear solution for python

    def climbingLeaderboard(ranked, player):
        res = []
        d = {}
        lowest = player[0]
        tmp = None
        n = 1
        
        for rank in ranked:
            if lowest >= rank:
                break
            
            if not tmp or rank != tmp:
                d[n] = rank
                n +=1
                tmp = rank
                
        res.append(n)
        d[n] = lowest
         
        for score in player[1:]:
            while n > 0 and d[n] <= score:
                n -= 1
            n += 1
            d[n] = score
            res.append(n)
            
        return res