Skip to content
LC-1331 Easy LeetCode

1331. Rank Transform of an Array

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 71% Topics: Array, Hash Table, Sorting
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(nlogn)
# Space: O(n)

class Solution(object):
    def arrayRankTransform(self, arr):
        """
        :type arr: List[int]
        :rtype: List[int]
        """
        return map({x: i+1 for i, x in enumerate(sorted(set(arr)))}.get, arr)

Solution from kamyu104/LeetCode-Solutions · MIT