Assign medal and placement ranks to athletes by score

Quick Overview

Given unique athlete scores, return each athlete's rank in the original input order, with medal names for the top three places and placement numbers as strings for everyone else. It tests ordering by a key while keeping track of original positions.

Assign medal and placement ranks to athletes by score

Company: Electronic Arts

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

You are given an integer array `score` of length `n`, where `score[i]` is the score of the athlete at index `i` in a competition. All the scores are unique. The athletes are placed by score: the athlete with the highest score is in 1st place, the athlete with the second highest score is in 2nd place, and so on. The placement of each athlete determines their rank: - 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 `n`th place athlete, the rank is their placement number as a string (the athlete in place `x` has rank `"x"`). Return an array `answer` of length `n` where `answer[i]` is the rank of the athlete at index `i`. ### Function Signature ```python def find_relative_ranks(score: list[int]) -> list[str]: ``` ### Rules - The output keeps the input order: `answer[i]` belongs to the athlete whose score is `score[i]`. - The medal strings are exact, with this capitalization and spacing: `"Gold Medal"`, `"Silver Medal"`, `"Bronze Medal"`. - Numeric ranks are plain decimal strings such as `"4"` or `"10"`. ### Constraints - `n == len(score)` - `1 <= n <= 10^4` - `0 <= score[i] <= 10^6` - All the values in `score` are unique. ### Examples ```text Input: score = [5, 4, 3, 2, 1] Output: ["Gold Medal", "Silver Medal", "Bronze Medal", "4", "5"] ``` The scores are already in descending order, so the placements are 1st through 5th in index order. ```text Input: score = [10, 3, 8, 9, 4] Output: ["Gold Medal", "5", "Bronze Medal", "Silver Medal", "4"] ``` From highest to lowest the scores are 10, 9, 8, 4, 3, which sit at indices 0, 3, 2, 4, 1. Index 0 gets gold, index 3 silver and index 2 bronze; index 4 is 4th and index 1 is 5th. ```text Input: score = [1, 2] Output: ["Silver Medal", "Gold Medal"] ``` With only two athletes, the higher score at index 1 takes gold and the score at index 0 takes silver. No bronze is awarded.

Overview: Given unique athlete scores, return each athlete's rank in the original input order, with medal names for the top three places and placement numbers as strings for everyone else. It tests ordering by a key while keeping track of original positions.

Electronic Arts logo
Electronic Arts
Nov 24, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

You are given an integer array score of length n, where score[i] is the score of the athlete at index i in a competition. All the scores are unique.

The athletes are placed by score: the athlete with the highest score is in 1st place, the athlete with the second highest score is in 2nd place, and so on. The placement of each athlete determines their rank:

  • 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 n th place athlete, the rank is their placement number as a string (the athlete in place x has rank "x" ).

Return an array answer of length n where answer[i] is the rank of the athlete at index i.

Function Signature

def find_relative_ranks(score: list[int]) -> list[str]:

Rules

  • The output keeps the input order: answer[i] belongs to the athlete whose score is score[i] .
  • The medal strings are exact, with this capitalization and spacing: "Gold Medal" , "Silver Medal" , "Bronze Medal" .
  • Numeric ranks are plain decimal strings such as "4" or "10" .

Constraints

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

Examples

Input: score = [5, 4, 3, 2, 1]
Output: ["Gold Medal", "Silver Medal", "Bronze Medal", "4", "5"]

The scores are already in descending order, so the placements are 1st through 5th in index order.

Input: score = [10, 3, 8, 9, 4]
Output: ["Gold Medal", "5", "Bronze Medal", "Silver Medal", "4"]

From highest to lowest the scores are 10, 9, 8, 4, 3, which sit at indices 0, 3, 2, 4, 1. Index 0 gets gold, index 3 silver and index 2 bronze; index 4 is 4th and index 1 is 5th.

Input: score = [1, 2]
Output: ["Silver Medal", "Gold Medal"]

With only two athletes, the higher score at index 1 takes gold and the score at index 0 takes silver. No bronze is awarded.