class Solution {
public int[] arrayRankTransform(int[] arr) {
Map<Integer, Queue<Integer>> map = new HashMap<>();
for (int i = 0; i < arr.length; i++) {
if (map.containsKey(arr[i]) == false) map.put(arr[i], new LinkedList<>());
map.get(arr[i]).offer(i);
}
Arrays.sort(arr);
int[] ans = new int[arr.length];
Map<Integer, Integer> record = new HashMap<>();
int rank = 0;
for (int i = 0; i < ans.length; i++) {
ans[map.get(arr[i]).poll()] = record.containsKey(arr[i]) ? record.get(arr[i]) : ++rank;
record.put(arr[i], rank);
}
return ans;
}
}