Trains the technique from
LeetCode 503Next Greater Element IIThis 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 survey crew walked a closed loop trail and wrote down the signed elevation change at each marker, in walking order, as the array deltas. The trail closes on itself, so once you step past the final marker you are back at marker 0.
Stand at a marker and keep walking forward around the loop until you reach a marker whose elevation change is strictly larger than the one you started from. Report that larger change. If you make a full circuit without finding one, report -1 instead.
Return an array answer of the same length, where answer[i] is what you report from marker i. Elevation changes may themselves be negative, and -1 is a perfectly legal change, so a reported -1 carries no extra meaning: it may be a change of -1 that you walked to, or it may be the signal that the loop holds nothing larger.
Example 1
Marker 0 finds 7 one step ahead. Marker 1 holds the largest change on the loop, so it reports -1. Marker 2 has to wrap past the end to reach 2.
Example 2
Both of the first two markers walk forward to -2. Marker 2 already holds the largest change, so it reports -1.
Example 3
An equal change is not a rise, so no marker ever finds one.
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 next_rise(deltas: list[int]) -> list[int]:public int[] nextRise(int[] deltas)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.