Trains the technique from
LeetCode 3660Jump Game IXThis 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 line of signal relay towers stands left to right, and heights[i] is the height of tower i. A drone carrying a signal repeater can hop between towers, and from tower i it may hop to tower j when either
j > i and heights[j] > heights[i], so the hop goes to the right and lands on a taller tower, orj < i and heights[j] < heights[i], so the hop goes to the left and lands on a shorter tower.The two towers of a hop need not be neighbours. The drone may make any number of hops, including none.
For each tower in turn, report the greatest height the drone can be standing on after starting there, counting the starting tower itself. Return those heights in tower order, so the entry at position i belongs to tower i.
Example 1
From tower 2, height 7, the drone hops right to tower 3, height 25, then left to tower 0, height 12, which is shorter, then right to tower 1, height 40, which is taller. Each of the other starts can reach tower 1 as well, so every answer here is 40.
Example 2
Tower 0 hops right to tower 1. Tower 2 has nothing to its right, and a left hop needs a strictly shorter tower while both towers to its left are 15 or more, so it stays put and answers with its own height.
Example 3
The heights fall from left to right, so no tower has a taller tower on its right or a shorter tower on its left. Each answer is the tower's own height.
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 max_value(heights: list[int]) -> list[int]:public int[] maxValue(int[] heights)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.