Skip to main content
Back to problems
Leetcode
Easy
Arrays
Sorting
Strings
Relative Ranks

Assign medals and placement strings to athletes based on their scores.

Acceptance 0%
Problem Statement

Problem

You are given an array of athlete scores where each score is unique. Rank the athletes from highest score to lowest score and return a new array of the same length containing their relative ranks.

The top three athletes should receive special labels:

  • Gold Medal for 1st place
  • Silver Medal for 2nd place
  • Bronze Medal for 3rd place

All remaining athletes should receive their rank number as a string, starting from 4.

Your task is to produce the rank label for each athlete in the original order of the input array.

Notes

  • Higher score means a better rank.
  • Scores are guaranteed to be distinct.
  • Preserve the original order in the output.

Input Format

  • An integer array score where score[i] is the score of the ii-th athlete.
  • All scores are distinct.

Output Format

  • Return an array of strings answer where answer[i] is the rank label for the ii-th athlete in the original order.

Constraints

  • 1score.length1041 \le score.length \le 10^4
  • 0score[i]1060 \le score[i] \le 10^6
  • All values in score are distinct.
Examples
Sample cases returned by the problem API.

Example 1

Input

score = [5,4,3,2,1]

Output

["Gold Medal","Silver Medal","Bronze Medal","4","5"]

Explanation

After sorting by score descending, the ranks are 5, 4, 3, 2, 1. The top three get medal labels, and the rest get their numerical rank as strings.

Example 2

Input

score = [10,3,8,9,4]

Output

["Gold Medal","5","Bronze Medal","Silver Medal","4"]

Explanation

Sorted descending, the scores rank as 10, 9, 8, 4, 3. We then place the corresponding labels back into the original order.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.