Relative Ranks of Athletes

Easy
9
59.6% Acceptance

In this lab, you will be working on a problem related to athletes in a competition and their ranks based on their scores. You will be given an integer array score of size n, where score[i] represents the score of the ith athlete. All the scores will be unique. Your task is to implement a function findRelativeRanks that returns an array containing the relative ranks of the athletes.

Here's a brief overview of the ranking system:

  • The 1st place athlete's rank is "Gold Medal".
  • The 2nd place athlete's rank is "Silver Medal".
  • The 3rd place athlete's rank is "Bronze Medal".
  • For the 4th place to the nth place athlete, their rank is their placement number (i.e., the xth place athlete's rank is "x").

The function you will implement is:

/** * @param {number[]} score * @return {string[]} */ var findRelativeRanks = function(score) { };

Examples

Example 1:

Input: score = [5, 4, 3, 2, 1] Output: ["Gold Medal", "Silver Medal", "Bronze Medal", "4", "5"] Explanation: The placements are [1st, 2nd, 3rd, 4th, 5th].

Example 2:

Input: score = [10, 3, 8, 9, 4] Output: ["Gold Medal", "5", "Bronze Medal", "Silver Medal", "4"] Explanation: The placements are [1st, 5th, 3rd, 2nd, 4th].

Example 3:

Input: score = [50, 40, 30, 20, 10] Output: ["Gold Medal", "Silver Medal", "Bronze Medal", "4", "5"] Explanation: The placements are [1st, 2nd, 3rd, 4th, 5th].

Constraints

  • n == score.length
  • 1 <= n <= 10^4
  • 0 <= score[i] <= 10^6
  • All the values in score are unique.