Leetcode 1256 Solution

This article provides solution to leetcode question 1256 (rank-transform-of-an-array)

https://leetcode.com/problems/rank-transform-of-an-array

Solution

class Solution:
    def arrayRankTransform(self, arr: List[int]) -> List[int]:
        arr2 = sorted(list(set(arr)))
        m = {v: i for i, v in enumerate(arr2)}
        return [m[v] + 1 for v in arr]