Relative Ranks

Problem Id: 506 Difficulty: Easy


Intuition

Solution


class Solution:
    def findRelativeRanks(self, nums: List[int]) -> List[str]:
        sort_nums = sorted(nums, reverse=True)
        score_rank = {sort_nums[i]: i + 1 for i in range(len(nums))}
        ans = []
        for num in nums:
            rank = score_rank[num]
            if rank == 1:
                ans.append('Gold Medal')
            elif rank == 2:
                ans.append('Silver Medal')
            elif rank == 3:
                ans.append('Bronze Medal')
            else:
                ans.append(str(rank))
        return ans