Sort by

recency

|

2368 Discussions

|

  • + 0 comments
    # Write your code here
        ranked_score = sorted(list(set(ranked)), reverse=True)
        
        arr = []
        for player_score in player:
            left, right = 0, len(ranked_score)
            while left < right:
                mid = (left + right) // 2
                if ranked_score[mid] > player_score:
                    left = mid + 1
                else:
                    right = mid
            arr.append(left + 1)
        return arr
    
  • + 1 comment

    Until the problem statement clearly specifies that the leaderboard is immutable (meaning the player's scores, as they are processed and a ranking is assigned, do not change the leaderboard), I don't believe the timeout test cases are valid. You need to KNOW that the leaderboard is intended to be immutable to achieve the needed performance. Am I wrong?

    • + 0 comments

      Or you need to know that player scores are always increasing, which is nowhere near a valid real world scenario.

  • + 0 comments

    Does this problem have these assumptions?

    1) Player scores will always be ascending? 2) Player scores do not mutate the leaderboard when they come in?

    If so, are these assumptions ever mentioned in the problem statement?

  • + 0 comments

    Here is my solution in C++:

    vector<int> climbingLeaderboard(vector<int> ranked, vector<int> player) {
        vector <int> result;
        
        auto start = unique(ranked.begin(), ranked.end());
        ranked.erase(start, ranked.end());
        sort(ranked.begin(), ranked.end());
        int index = 0;
        
        for (auto it : player) {
            while (index < ranked.size() && it >= ranked[index]) index++;
            result.push_back(ranked.size() - index + 1);
        }
        return result;
    }
    
  • + 0 comments

    This times out on large ranked input > 100k

    r = sorted(list(set(ranked)), reverse=True)

    z = len(r)
    w = len(player)
    low = r[z-1]
    high = r[0]
    score = list()
    
    for x in range(0,w):
        for y in range(0,z):
    
            if (player[x] < low):
                score.append(z+1)
                break
            if (player[x] >= high):
                score.append(1)
                break       
            if (player[x] >= r[y]):
                score.append(y+1)
                break
    
    return(score)