0
Leetcode Problem 506. Relative Ranks
506. Relative Ranks
AI Mock Interview
Leetcode Solutions
Sorting and Mapping Approach
Solution Idea
Algorithm Steps
Code Implementation
Complexity Analysis
Create a list of pairs where each pair consists of a score and its original index.
Sort this list in descending order based on the scores.
Initialize an answer array of strings with the same length as the input score array.
Iterate through the sorted list of pairs.
For the top three scores, assign 'Gold Medal', 'Silver Medal', and 'Bronze Medal' respectively.
For the rest, assign the rank as a string, which is the 1-based index in the sorted list.
Place these ranks into the answer array at the original indices.
Return the answer array.
Hash Map and Sorting Approach
Ask Question
Programming Language
Purpose:
General Question
Debug My Code
image/screenshot of info
(optional)
[+]
Full Screen
Loading...
Get Answer
Suggested Answer
Answer
Full Screen
Copy Answer Code
Loading...