Problem Statement
Given an integer array ARR
of size N
, replace each element of this array with its corresponding rank.
Explanation
The rank of an element is an integer between 1 and N
(inclusive) that represents its size relative to other elements in the array. Here are the rules to determine the rank:
1. Ranks start from 1.
2. Larger elements receive larger ranks. Equal elements share the same rank.
3. Ranks should be assigned as small as possible.
Input
The first line contains an integer T
, the number of test cases.
Following is 2*T
lines describing the test cases:
For each test case, the first line contains an integer N
(the number of elements in ARR
).
The second line contains N
space-separated integers, the elements of ARR
.
Output
For each test case, print the elements of ARR
separated by spaces, with each element replaced by its rank.
Example
Input:
2
5
50 30 20 40 10
3
100 200 100
Output:
5 3 2 4 1
2 3 2
Constraints
1 <= T <= 50
1 <= N <= 10^4
-10^9 <= ARR[i] <= 10^9
- The array
ARR[i]
denotes thei
th element of the array.
Note
You do not need to print anything; instead, return the integer array ARR
with each element replaced by its rank.
Be the first one to answer
Add answer anonymously...
Top Groww Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app