Problem
A mountain is a contiguous stretch of a list with length at least 3 that strictly increases to a peak and then strictly decreases. The peak cannot be the first or last element of the stretch. Given a list arr, return the length of the longest mountain, or 0 if there is none.
Example 1
- Input
- arr = [2, 1, 4, 7, 3, 2, 5]
- Output
- 5
- Why
- [1, 4, 7, 3, 2]
Example 2
- Input
- arr = [2, 2, 2]
- Output
- 0
- Why
- flat is not a mountain
Example 3
- Input
- arr = [1, 2, 3]
- Output
- 0
- Why
- no way down
Can you do it in one pass with O(1) extra space?
Constraints
1 <= arr.length <= 10^40 <= arr[i] <= 10^4