All practice tasks

Coding (Algo)

Rank Records Without Losing Their Positions

Sorting · Easy

A report ranks records by numeric value but must attach each rank back to the original record. Equal values receive consecutive ranks in original arrival order. Shared competition ranks are not used.

Return each original record’s zero-based position in a stable ascending ordering of all records.

Input

Call

  • Implement solve(input) and return the result. The provided adapter handles JSON input and output.

Input shape

{ nums: integer[] }

Fields

  • nums is an array of signed integers. Repeated values at different positions are separate entries.

Output

Return value

  • Return an integer array aligned with the original input. Its entries form a permutation of 0 through n - 1.
  • Equal values get different consecutive ranks; the earlier original index gets the smaller rank.

Constraints

  • 0 <= nums.length <= 100000; -1000000000 <= nums[i] <= 1000000000.
  • All totals and counts fit exactly in a safe JSON integer.

Examples

Example 1

{
  "nums": [
    5,
    2,
    5
  ]
}

Returns

[
  1,
  0,
  2
]

Example 2

{
  "nums": [
    3,
    2,
    1
  ]
}

Returns

[
  2,
  1,
  0
]

Required complexity

O(n log(n + 1)) time and O(n) auxiliary space

What this task practices

Rank Records Without Losing Their Positions is a coding (algo) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as easy difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.