You are given an array of N integers.
Your task is to replace each element with its rank when the array is sorted in ascending order.
The smallest element gets rank 1.
The next smallest gets rank 2, and so on.
If two elements are equal, they share the same rank.
Example 1
Input
20 15 26 2 98 6
Output
4 3 5 1 6 2
Explanation
Sorted array:
2 6 15 20 26 98
Ranks:
2 → 1
6 → 2
15 → 3
20 → 4
26 → 5
98 → 6
Final ranked array:
4 3 5 1 6 2