All problems
0115EasyArrayHash TableSorting

Core Sample Rank Labels

Tracked in this browser only
Write code

Trains the technique from

LeetCode 1331Rank Transform of an Array

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A survey crew drills a line of core samples and logs the elevation of each sample's bedrock contact in metres against the site datum, so a logged value may be below the datum, on it, or above it. The log arrives as readings in drilling order. A shift that drilled nothing at all leaves the log empty.

The written report hides the raw elevations and prints rank labels instead. Labels are assigned like this:

  • The deepest elevation on the log is labelled 1.
  • Samples logging the identical elevation carry the identical label.
  • Labels run without gaps: the next elevation upwards from a labelled one takes the next whole number.

Return the labels in drilling order, one per reading.

Examples

Example 1

Input
readings = [-15, 40, -15, 8]
Output
[1, 3, 1, 2]

Three distinct elevations appear, -15 then 8 then 40, so they take labels 1, 2 and 3, and the repeated -15 keeps label 1 in both positions.

Example 2

Input
readings = [0, -4, -4, 7, 7, 12]
Output
[2, 1, 1, 3, 3, 4]

The distinct elevations run -4, 0, 7, 12, so 0 lands on label 2 while each repeated elevation reuses its own label.

Example 3

Input
readings = [-7, -8]
Output
[2, 1]

Only two samples were drilled and -8 is the deeper of the pair, so it takes label 1 and -7 takes label 2.

Constraints

  • 0 <= readings.length <= 10^5
  • -10^9 <= readings[i] <= 10^9

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def rank_core_samples(readings: list[int]) -> list[int]:
Java
public int[] rankCoreSamples(int[] readings)
September 7
Apply