Replace every element of nums with its dense rank: the smallest value gets rank 1, equal values get the same rank, and ranks are consecutive integers with no gaps. Return the list of ranks in the original order.
Examples
Input: nums = [40, 10, 20, 20]
Output: [3, 1, 2, 2]
Input: nums = [100, 100, 100]
Output: [1, 1, 1]
Input: nums = [37, 12, 28, 9, 100, 56, 80, 5, 12]
Output: [5, 3, 4, 2, 8, 6, 7, 1, 3]
Constraints
0 <= len(nums) <= 10**5-10**9 <= nums[i] <= 10**9- Target: O(n log n) time.
Goals
- Map distinct values to consecutive ranks
- Look up each element's rank in O(1) after preprocessing