Assign medals and placement strings to athletes based on their scores.
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 Medalfor 1st placeSilver Medalfor 2nd placeBronze Medalfor 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
scorewherescore[i]is the score of the -th athlete. - All scores are distinct.
Output Format
- Return an array of strings
answerwhereanswer[i]is the rank label for the -th athlete in the original order.
Constraints
- All values in
scoreare distinct.
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.