Relative Ranks

EasyHeapheap

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

You are given an array score where score[i] is the score of the i-th athlete. All scores are **distinct**. Athletes are placed by score: the highest score is 1st place, the next highest is 2nd, and so on. Return an array answer of the same length where answer[i] is athlete i's rank label: "Gold Medal" for 1st place, "Silver Medal" for 2nd, "Bronze Medal" for 3rd, and the placement number as a string (e.g. "4") for everyone else.

Examples

Input: score = [5,4,3,2,1]
Output: ["Gold Medal","Silver Medal","Bronze Medal","4","5"]
Scores are already in descending order.
Input: score = [10,3,8,9,4]
Output: ["Gold Medal","5","Bronze Medal","Silver Medal","4"]
Sorted descending: 10, 9, 8, 4, 3.

Constraints

  • 1 <= score.length <= 10^4
  • 0 <= score[i] <= 10^6
  • All values in `score` are distinct

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More heap problems