• + 0 comments

    Finally managed to crack it after persevering so many times.. Here is my C++ solution. 1. I have converted the ranking vector to a set , to remove duplicates, thus giving me the actual ranking order, i.e. 1 to size of set 2. I have converted the set back to a vector to get the index position if we were to insert Alice's score, using lower_bound , remember lower_bound returns an iterator past the index 3. I work out potential idices and push them to the res vector. 4. I also check existing items in both ranking/player.. the code follows here..

    vector climbingLeaderboard(vector &ranked, vector player) { vector res;

    set<int> s(ranked.begin(), ranked.end());
    vector<int> j(s.begin(), s.end());
    int sz_s = j.size();
    
    int idx = 0;
    for (auto p : player)
    {
        auto iter = lower_bound(j.begin(), j.end(), p);
        idx = iter - j.begin();
        if (*iter == p )
        {
            idx = sz_s - idx;
        }
        else
        {
            idx = sz_s + 1 - idx;
        }
        res.push_back(idx);
    }
    
    return res;
    

    }