FastPrepRank Transform an Array
Problems/Rank Transform an Array

Rank Transform an Array

Agoda logoAgoda● EasyFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names the full, well-known rank transform but does not keep its examples.

Our version is about 94% the same as the reported question.

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

Interview reports that mention this question

  • Agoda Staff Backend OA Questions: 5 Experiences
All Agoda interview questionsSee Agoda hiring insights
Saved
class Solution {
    public int[] arrayRankTransform(int[] values) {
        // Write your solution here.
    }
}
Checking account…