Rank Transform of an Array
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Given an integer array arr, replace every element with its rank and return the resulting array.
Ranks start at 1 for the smallest distinct value. Equal elements get the same rank, and ranks have no gaps: the rank of a value is 1 plus the number of distinct values strictly smaller than it.
An empty input returns an empty array. Target O(n log n) time.
Examples
Constraints
- 0 <= arr.length <= 10^5
- -10^9 <= arr[i] <= 10^9
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.