---
# System prepended metadata

title: 1331. Rank Transform of an Array
tags: [Leetcode, Easy, HashMap]

---

# 1331. Rank Transform of an Array
###### tags: `Leetcode` `Easy` `HashMap`
Link: https://leetcode.com/problems/rank-transform-of-an-array/
## Code
```java=
class Solution {
    public int[] arrayRankTransform(int[] arr) {
        int[] A = Arrays.copyOf(arr, arr.length);
        Arrays.sort(A);
        Map<Integer, Integer> rank = new HashMap<>();
        for(int num:A) rank.putIfAbsent(num, rank.size()+1);
        for(int i=0; i<arr.length; i++){
            A[i] = rank.get(arr[i]);
        }
        return A;
    }
}
```