• + 0 comments

    Solution for c#: // the if !added at the end is in case the player is ranked in last position.

    public static List climbingLeaderboard(List ranked, List player) { List playerRanks = new List(); int position = 0; int nextIndex = 0; int prev = -1;

        for(int i = player.Count-1; i >= 0; i--){
            bool added = false;
            for(int j = nextIndex; j < ranked.Count; j++){               
                if (player[i] >= ranked[j])
                {
                    playerRanks.Add(position + 1);
                    added = true;
                    break;
                }
                nextIndex++;
                if(ranked[j] != prev){
                    prev = ranked[j];
                    position++;
                }               
            }
            if(!added){
               playerRanks.Add(position+1);
            }
        }
    
        playerRanks.Reverse();     
        return playerRanks;
    }