Trains the technique from
LeetCode 845Longest Mountain in 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.
Ground heights along a track are given as arr.
A ridge is a stretch of at least three heights that rises strictly for a while and then falls strictly for a while: there is a position inside it, neither end, where everything before rises strictly up to it and everything after falls strictly away from it.
Return the length of the longest ridge, or 0 when the track holds none.
Example 1
The heights rise 3, 8, 14 and then fall 9, 4, which is a ridge of five. The fall stops at the level pair of fours, so the ridge cannot reach further.
Example 2
The track only rises, so there is no peak and no ridge.
Example 3
The two level heights in the middle mean neither is a peak, since a peak needs its neighbours strictly lower.
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_mountain(arr: list[int]) -> int:public int longestMountain(int[] arr)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.