Jump Game V
Real-world version: Longest Descent RunThe statement here is our own: the same inputs, outputs and technique.
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:
jis a different position with|i - j| <= reach;height[j] < height[i], so every hop goes strictly downwards;- every ledge strictly between
iandjis also lower thanheight[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.
Examples
Example 1
- Input
- height = [10, 1, 9], reach = 2
- Output
- 3
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
- Input
- height = [4, 4, 4, 4], reach = 2
- Output
- 1
No hop is legal, because no ledge is strictly lower than another. A run therefore touches only the ledge it starts on.
Example 3
- Input
- height = [5, 5, 5, 1, 5, 5, 5], reach = 3
- Output
- 2
Starting on the ledge at position 2, the climber hops one place right onto the ledge of height 1. That run touches two ledges.
Constraints
- 1 <= height.length <= 1000
- 1 <= height[i] <= 10^5
- 1 <= reach <= height.length
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def longest_descent_run(height: list[int], reach: int) -> int:public int longestDescentRun(int[] height, int reach)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 14 test cases: 14 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Non-overlapping IntervalsReal-world version: Drop the Clashing Kiln RunsMedium
- Largest Divisible SubsetReal-world version: Rate-Compatible Reel BundlesMedium
- Two Best Non-Overlapping EventsReal-world version: Two Studio BookingsMedium
- Longest String ChainReal-world version: Longest Chain of Grown LabelsMedium