• + 1 comment

    My code doesn't pass the execution time limits, does anyone know why?. Here it is:

    '''finds the position of the player based on their score. We compare their score with the scores of all the other players.'''
    
    def order(ranked, element):    
        storage=[]
        storage.append((1, ranked[0]))
        index=2
        for score in ranked[1:]:
            if storage[-1][1]==score:
                continue
            else:
                ele=(index, score)
                storage.append(ele)
                index+=1        
        for pair in storage:        
            if (pair[1]==element):
                return pair[0] 
    
    '''
    This will insert the player's score in its correct position in the ranked list. Then it will find the position of that score in the ranked list using the order function. This will be stored in the outList, which is what will be returned 
    '''
    def climbingLeaderboard(ranked, player):
        # Write your code here
        outList = []
        for score in player:
            flag=True
            if score > ranked[0]:
                ranked.insert(0, score)
                outList.append(order(ranked, score))
                continue
            for j in range(0, len(ranked)-1):
                if ranked[j] >= score >= ranked[j+1]:
                    ranked.insert(j+1, score)
                    outList.append(order(ranked, score))
                    flag = False
                    break
            if flag:
                ranked.append(score)
                outList.append(order(ranked, score))
        return outList