Rank Transform an Array
Updated
Problem statement
Given an integer array values, replace every value with its rank.
- The smallest distinct value has rank
1. - Larger distinct values receive consecutive larger ranks.
- Equal values receive the same rank.
Return the transformed array in the original element order.
Function
arrayRankTransform(values: int[]) → int[]Examples
Example 1
values = [40,10,20,30]return = [4,1,2,3]The ascending distinct values are 10, 20, 30, 40, with ranks 1, 2, 3, 4.
Example 2
values = [100,100,100]return = [1,1,1]There is only one distinct value, so every position receives rank 1.
Constraints
1 <= values.length <= 10^5-10^9 <= values[i] <= 10^9
More Agoda interview questions
- Sort Ones, Twos, and Threes In PlacePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Molecular Weight of a Grouped FormulaONSITE INTERVIEW · Seen Oct 2026
- Minimum Daily Printing LimitONSITE INTERVIEW · Seen Aug 2026
- Climb Stairs with One, Two, or Three StepsONSITE INTERVIEW · Seen Aug 2026
- Minimum Absolute Difference PairsONSITE INTERVIEW · Seen Jun 2026
- Feasibility of Printing Within Given DaysONSITE INTERVIEW · Seen May 2026
- 3SumONSITE INTERVIEW · Seen May 2026
- Can Place FlowersPHONE SCREEN · Seen Nov 2026
- Reverse Words in a StringPHONE SCREEN · Seen Nov 2026
- Disk Space Window AnalyzerPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Map and Accumulate Learning QueriesPalantir · ONSITE INTERVIEWPalantir interview questions
- Filter Anagrams of a TargetMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Deduplicate Logs: Keep FirstGoogle · ONSITE INTERVIEWGoogle interview questions
- Loyal Customers by Two-Day Product VarietyAmazon · ONSITE INTERVIEW
- Restaurant Vote LeadersZipRecruiter · PHONE SCREEN · ONSITE INTERVIEWZipRecruiter interview questions
- High-Severity Counts by Search TypeChainalysis · ONSITE INTERVIEWChainalysis interview questions
- Intersection of Two ListsJP Morgan Chase · ONSITE INTERVIEWJP Morgan Chase interview questions
- Pair Left and Right Socks by IDRoblox · ONSITE INTERVIEWRoblox interview questions
- Net Position Calculation from API SnapshotsHeadlands Technologies · ONSITE INTERVIEWHeadlands Technologies interview questions
- Count Word FrequenciesBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions