Rank Transform of an Array
Replace each item of arr by its rank: the smallest distinct value has rank 1, the next smallest distinct value has rank 2, and so on. Equal values share the same rank.
Return the list of ranks in the original order.
Example 1
arr [40,10,20,30]
returns [4,1,2,3]
10 is rank 1, 20 rank 2, 30 rank 3, 40 rank 4.
Example 2
arr [100,100,100]
returns [1,1,1]
All equal, so all rank 1.
Constraints
0 <= len(arr) <= 30-100 <= arr[i] <= 100
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.