• + 0 comments

    For those using C++, I found this way can pass all the time limited case The idea is same as many of here: find the first one greater than player's score, but using maximum of built-in function to push up the performance:

    vector<int> climbingLeaderboard(vector<int> ranked, vector<int> player) {
        int n = ranked.size(); int m = player.size();
        
        // Xu ly leaderboard
        
        vector<int> stored;
        for (int i=0; i<n; i++) {
            if (i==0) stored.push_back(ranked[i]);
            else {
                if (ranked[i-1]!=ranked[i]) stored.push_back(ranked[i]);
            }
        }
        
        // Xu ly mang player
        vector<int> res; 
        for (int i=0; i<m; i++) {
            int ans = upper_bound(stored.rbegin(),stored.rend(),player[i]) - stored.rbegin();
            int rank = 1+stored.size() - abs(ans);
            res.push_back(rank);
        }
    		
        
        return res;
    }