Trains the technique from
LeetCode 1340Jump Game VThis 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 climbing wall has a row of ledges. height[i] is the height of the ledge at position i, and a climber can hop between ledges along the row.
Standing on ledge i, the climber may hop to ledge j when all three hold:
j is a different position with |i - j| <= reach;height[j] < height[i], so every hop goes strictly downwards;i and j is also lower than height[i], so nothing on the way blocks the hop.The climber picks any ledge to start on and then hops as many times as they like, possibly not at all. Return the largest number of ledges a single run can touch, counting the ledge it starts on.
Example 1
Starting on the ledge of height 10, the climber hops two places right to the ledge of height 9, since 9 is lower than 10 and the ledge of height 1 in between is lower too, and then hops back one place left to the ledge of height 1. That run touches three ledges.
Example 2
No hop is legal, because no ledge is strictly lower than another. A run therefore touches only the ledge it starts on.
Example 3
Starting on the ledge at position 2, the climber hops one place right onto the ledge of height 1. That run touches two ledges.
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 longest_descent_run(height: list[int], reach: int) -> int:public int longestDescentRun(int[] height, int reach)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.