Trains the technique from
LeetCode 1331Rank Transform of an ArrayThis 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:
1.Return the labels in drilling order, one per reading.
Example 1
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
The distinct elevations run -4, 0, 7, 12, so 0 lands on label 2 while each repeated elevation reuses its own label.
Example 3
Only two samples were drilled and -8 is the deeper of the pair, so it takes label 1 and -7 takes label 2.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def rank_core_samples(readings: list[int]) -> list[int]:public int[] rankCoreSamples(int[] readings)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.