Climbing the Leaderboard

  • + 0 comments

    Python 3, no sorting, no extra memory

    def climbingLeaderboard(ranked, player):
        result  = []
        i = 0
        currplace = 1
        pindx = len(player) - 1
        ranked.append(0)
        
        while i < len(ranked):
            if pindx < 0:
                return result
                            
            lastsc = ranked[i]
            
            if player[pindx] >= ranked[i]:
                result .insert(0, currplace)
                pindx -= 1
            else:
                i += 1
                if ranked[i] != lastsc:
                    currplace += 1
          
        return result