Trains the technique from
LeetCode 941Valid Mountain ArrayThis 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 walks a straight line and records the ground elevation at each station, giving heights in walking order.
The line is a single ridge when both of the following hold:
p, neither the first nor the last, such that the elevations strictly increase from the first station up to p, and strictly decrease from p on to the last station.Strictly means no two neighbouring stations on either side may record the same elevation. Return true when the line is a single ridge and false otherwise.
Example 1
Station 1 is neither the first nor the last, the elevation rises from 0 to 3 before it, and falls from 3 to 1 after it.
Example 2
The elevations keep rising to the last station, so there is no station strictly inside the line with a fall after it.
Example 3
Stations 1 and 2 both record 2. That pair is neither a strict rise nor a strict fall, so no station splits the line into the two required parts.
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 is_single_ridge(heights: list[int]) -> bool:public boolean isSingleRidge(int[] heights)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.