Trains the technique from
LeetCode 493Reverse PairsThis 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 transmitter logs one signed power level per sample into levels, in the order the samples were taken. Levels are calibration offsets, so they may be negative, zero or positive.
An analyst wants to know how often the signal fell away sharply between two samples, no matter how far apart those samples sat. Sample i and sample j make a steep decline when i < j and levels[i] > 2 * levels[j], using ordinary signed arithmetic. The comparison is strict: a level that is exactly double the later one does not qualify.
Count the steep declines in the log and return that count. Note that a pair is judged only by its two levels and by which sample came first; the samples in between are irrelevant.
Example 1
The pair of samples holding 6 then 1 qualifies because 6 beats 2, and 6 then 2 qualifies because 6 beats 4. The pair holding 4 then 2 fails, since 4 is exactly double and not more.
Example 2
Only -1 followed later by -5 qualifies, because doubling -5 gives -10 and -1 sits above it.
Example 3
Doubling the later level gives exactly the earlier one, and the rule needs a strict excess, so nothing is counted.
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 steep_declines(levels: list[int]) -> int:public int steepDeclines(int[] levels)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.