Given an array of scores, assign different ranks based on their position in the sorted array
Intuition
Sort the array and assign based on the sorted array.
Approach
in C++, we can use the property of the container map
to solve this problem, the map is constructed so that the key is the score and the value is the index of the score.
Complexity
Time complexity: construct the map $$O(n\log n)$$
Space complexity: store the scores and indexes $$O(n)$$
Code
|
|