Tap here to switch tabs
Problem
Submissions

Problem: Rank Transform of an Array

med
30 min
Try to solve the Rank Transform of an Array problem.

Statement

Given an integer array arr, replace each element with its rank when the distinct values of arr are sorted in strictly increasing order.

The rank rules are:
The smallest distinct value has rank 11.
If a value is the kk th smallest distinct value, its rank is kk.
Equal values must receive the same rank.

Return the resulting array of ranks in the same order as arr.

Note: Ranks are assigned based only on the sorted order of distinct values, not on the original indices.

Constraints:

  • 0≤0 \leq arr.length ≤105\leq 10^5

  • −109≤-10^9 \leq arr[i] ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Rank Transform of an Array

med
30 min
Try to solve the Rank Transform of an Array problem.

Statement

Given an integer array arr, replace each element with its rank when the distinct values of arr are sorted in strictly increasing order.

The rank rules are:
The smallest distinct value has rank 11.
If a value is the kk th smallest distinct value, its rank is kk.
Equal values must receive the same rank.

Return the resulting array of ranks in the same order as arr.

Note: Ranks are assigned based only on the sorted order of distinct values, not on the original indices.

Constraints:

  • 0≤0 \leq arr.length ≤105\leq 10^5

  • −109≤-10^9 \leq arr[i] ≤109\leq 10^9