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
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 31ms, memory 35.6MB, accepted 2025-12-30.
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]