Tap here to switch tabs
Problem
Submissions

Problem: Relative Ranks

Relative Ranks orders unique athlete scores from highest to lowest, returning the original-order array with Gold, Silver, and Bronze Medals for the top three and numeric ranks for everyone else.

Statement

You are given an integer array score of size n, where score[i] represents the score of the ithi^{ {th}} athlete in a competition. All scores are guaranteed to be unique.

The athletes are awarded ranks based on their scores, where the athlete with the highest score receives the 1st1^{ {st}} place rank, the athlete with the second highest score receives the 2nd2^{ {nd}} place rank, and so on.

The placement ranks are decided as follows:

  • The 1st1^{ {st}} place athlete is awarded "Gold Medal".

  • The 2nd2^{ {nd}} place athlete is awarded "Silver Medal".

  • The 3rd3^{ {rd}} place athlete is awarded "Bronze Medal".

  • For the 4th4^{ {th}} place to the nthn^{ {th}} place athlete, their rank is their placement number represented as a string (i.e., "$x$" for the xthx^{ {th}} place).

Return an array answer of size n where answer[i] is the rank of the ithi^{ {th}} athlete.

Constraints:

  • n == score.length

  • 1≤1 \leq n ≤104\leq 10^4

  • 0≤0 \leq score[i] ≤106\leq 10^6

  • All the values in score are unique.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Relative Ranks

Relative Ranks orders unique athlete scores from highest to lowest, returning the original-order array with Gold, Silver, and Bronze Medals for the top three and numeric ranks for everyone else.

Statement

You are given an integer array score of size n, where score[i] represents the score of the ithi^{ {th}} athlete in a competition. All scores are guaranteed to be unique.

The athletes are awarded ranks based on their scores, where the athlete with the highest score receives the 1st1^{ {st}} place rank, the athlete with the second highest score receives the 2nd2^{ {nd}} place rank, and so on.

The placement ranks are decided as follows:

  • The 1st1^{ {st}} place athlete is awarded "Gold Medal".

  • The 2nd2^{ {nd}} place athlete is awarded "Silver Medal".

  • The 3rd3^{ {rd}} place athlete is awarded "Bronze Medal".

  • For the 4th4^{ {th}} place to the nthn^{ {th}} place athlete, their rank is their placement number represented as a string (i.e., "$x$" for the xthx^{ {th}} place).

Return an array answer of size n where answer[i] is the rank of the ithi^{ {th}} athlete.

Constraints:

  • n == score.length

  • 1≤1 \leq n ≤104\leq 10^4

  • 0≤0 \leq score[i] ≤106\leq 10^6

  • All the values in score are unique.