Trains the technique from
LeetCode 2653Sliding Subarray BeautyThis 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 calibration log holds readings, the drift each sensor sweep measured. A negative reading means the sweep came out below the reference.
Every block of span consecutive readings gets a drift mark, worked out like this. Take the negative readings in the block and put them in increasing order, keeping repeats. If that ordering holds at least rank readings, the block's drift mark is the rank-th reading in it. Otherwise the block's drift mark is 0.
Return the drift marks of every block, in the order the blocks appear from the start of the log to its end.
Example 1
The first block is [-2, 4, -3]; its negative readings in increasing order are -3 and -2, and the second of those is -2. The last block is [0, -50, 5], which holds only one negative reading, so its mark is 0.
Example 2
The block [-2, -2, -1] orders its negative readings as -2, -2, -1, and the second of those is -2. The block [-2, -1, -4] orders them as -4, -2, -1, so its mark is -2 as well.
Example 3
No block holds a negative reading, so every mark is 0.
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 drift_marks(readings: list[int], span: int, rank: int) -> list[int]:public int[] driftMarks(int[] readings, int span, int rank)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.