506. Relative Ranks Easy

@problem@discussion
#Array#Sorting#Heap (Priority Queue)



1/**
2 * [506] Relative Ranks
3 *
4 * You are given an integer array score of size n, where score[i] is the score of the i^th athlete in a competition. All the scores are guaranteed to be unique.
5 * The athletes are placed based on their scores, where the 1^st place athlete has the highest score, the 2^nd place athlete has the 2^nd highest score, and so on. The placement of each athlete determines their rank:
6 * 
7 * 	The 1^st place athlete's rank is "Gold Medal".
8 * 	The 2^nd place athlete's rank is "Silver Medal".
9 * 	The 3^rd place athlete's rank is "Bronze Medal".
10 * 	For the 4^th place to the n^th place athlete, their rank is their placement number (i.e., the x^th place athlete's rank is "x").
11 * 
12 * Return an array answer of size n where answer[i] is the rank of the i^th athlete.
13 *  
14 * Example 1:
15 * 
16 * Input: score = [5,4,3,2,1]
17 * Output: ["Gold Medal","Silver Medal","Bronze Medal","4","5"]
18 * Explanation: The placements are [1^st, 2^nd, 3^rd, 4^th, 5^th].
19 * Example 2:
20 * 
21 * Input: score = [10,3,8,9,4]
22 * Output: ["Gold Medal","5","Bronze Medal","Silver Medal","4"]
23 * Explanation: The placements are [1^st, 5^th, 3^rd, 2^nd, 4^th].
24 * 
25 *  
26 * Constraints:
27 * 
28 * 	n == score.length
29 * 	1 <= n <= 10^4
30 * 	0 <= score[i] <= 10^6
31 * 	All the values in score are unique.
32 * 
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/relative-ranks/
37// discuss: https://leetcode.com/problems/relative-ranks/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42    pub fn find_relative_ranks(score: Vec<i32>) -> Vec<String> {
43        vec![]
44    }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51    use super::*;
52
53    #[test]
54    fn test_506() {
55    }
56}
57


Back
© 2025 bowen.ge All Rights Reserved.