FastPrepArray Rank Transform
Problems/Array Rank Transform

Array Rank Transform

Tata Consultancy Services logoTata Consultancy Services● EasyOA

Updated Jul 2026

QuestionFunctionExamples

Problem statement

You are given an integer array arr. Replace each value with its rank after sorting all distinct values in increasing order.

The smallest distinct value has rank 1. Equal values must receive the same rank, and ranks must be consecutive with no gaps.

Return the transformed array in the original order.

Function

arrayRankTransform(arr: int[]) → int[]

Examples

Example 1

arr = [40,10,20,30]return = [4,1,2,3]

The sorted distinct values are 10,20,30,40, so their ranks are 1,2,3,4.

Example 2

arr = [100,100,100]return = [1,1,1]

All values are equal, so all positions receive the same smallest rank.

More Tata Consultancy Services Online Assessment questions

  • EV Charging Cost OptimizationOA · Seen Sep 2026
  • Maximum Gap After SortingOA · Seen Sep 2026
  • Count Array InversionsOA · Seen Aug 2026
  • Count Smaller Prior ElementsOA · Seen Aug 2026
  • Gym Fees CalculatorOA · Seen Mar 2026

Similar questions at other companies

  • Build the Task HierarchyPendo · OA
  • Macaron Order with Set DiscountsShopify · OAShopify interview questions
  • Count User Mentions in Chat MessagesRamp · OARamp interview questions
  • Word Frequency Counts in Alphabetical OrderAbridge · OAAbridge interview questions
  • Minimum Magic Stones After MergesElevenLabs · OAElevenLabs interview questions
  • Items SortAkuna Capital · OAAkuna Capital interview questions
  • Count Cross-Array Target-Sum PairsVisa · OAVisa interview questions
  • Find Max Health SumAmazon · OA
  • Influencers SquadTikTok · OATikTok interview questions
  • Count Teams Outscoring a Target TeamBloomberg LP · OABloomberg LP interview questions
All Tata Consultancy Services interview questionsSee Tata Consultancy Services hiring insights
Saved
class Solution {
    public int[] arrayRankTransform(int[] arr) {
      // write your code here
    }
}
Checking account…