LeetCode solutions

1256. Rank Transform of an Array

My accepted Python solution to LeetCode problem 1256, Rank Transform of an Array, running in 31ms.

  • Difficulty: Easy
  • Python
  • Runtime 31ms
  • Memory 35.6MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 31ms, memory 35.6MB, accepted 2025-12-30.

python
class Solution:
    def arrayRankTransform(self, arr: List[int]) -> List[int]:
        sorted_unique = sorted(set(arr))
        rank_map = {val: i+1 for i, val in enumerate(sorted_unique)}
        return [rank_map[x] for x in arr]

Source