values. Replace every number with its rank and return the resulting array.
Ranks work like this:
- a rank is an integer starting from 1;
- a larger number gets a larger rank, and equal numbers get equal ranks;
- ranks are as small as possible, so they go consecutively with no gaps.values=[7, -2, 7, 0] → [3, 1, 3, 2]
The distinct values in increasing order are -2, 0, 7, with ranks 1, 2, 3. Both 7s get rank 3.
values=[50, 40, 30] → [3, 2, 1]
The smallest is 30 with rank 1; the largest is 50 with rank 3.
values=[] → []
values=[7, -2, 7, 0]
[3, 1, 3, 2]
Run checks the first 3 tests in your browser. Submit checks all 115 tests on the server, hidden ones included.