Skip to content

Relative Ranks

EasyHeap / Priority Queue
Decode it first. Clues, constraints, pattern and plan before any code.

Athletes finished a race with scores score, where score[i] belongs to athlete i. All scores are different, and a higher score is better.

Give each athlete their placement: first place gets "Gold Medal", second gets "Silver Medal", third gets "Bronze Medal", and everyone from fourth place on gets their place number as a string ("4", "5", ...). Return the answers in the original order of the athletes.

score = [5, 4, 3, 2, 1]    →  ["Gold Medal", "Silver Medal", "Bronze Medal", "4", "5"]
score = [10, 3, 8, 9, 4]   →  ["Gold Medal", "5", "Bronze Medal", "Silver Medal", "4"]

Constraints

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