• + 0 comments

    C# Code

    I guess O(n²) doesn't work on C#. Time limit exceed error. Perfect logic though I think.

    public static List<int> climbingLeaderboard(List<int> ranked, List<int> player)
        {
            List<int> ranking = new List<int>();
            int num_of_players = player.Count();
            ranked = ranked.Distinct<int>().OrderByDescending(s => s).ToList();
            
            foreach(int p in player)
            {
                int temp_rank = 1;
                for(int i = 0; i < ranked.Count; i++)
                {
                    if(p<ranked[i])
                    {
                        temp_rank++;
                    }
                    else
                    {
                        break;
                    }
                }
                ranking.Add(temp_rank);
            }
            return ranking;
        }