Given an integer array arr, return the length of the longest contiguous subarray that forms a mountain.
A subarray arr[l..r] is a mountain if all of the following are true:
A mountain has length at least
There exists an index p with l < p < r such that arr[l] < arr[l+1] < ... < arr[p] and arr[p] > arr[p+1] > ... > arr[r].
In other words, the values strictly increase up to a single peak, then strictly decrease after the peak.
If no mountain exists in arr, return
Note: Consider whether you can solve this in a single pass using
extra space.
Constraints:
arr.length
arr[i]
Given an integer array arr, return the length of the longest contiguous subarray that forms a mountain.
A subarray arr[l..r] is a mountain if all of the following are true:
A mountain has length at least
There exists an index p with l < p < r such that arr[l] < arr[l+1] < ... < arr[p] and arr[p] > arr[p+1] > ... > arr[r].
In other words, the values strictly increase up to a single peak, then strictly decrease after the peak.
If no mountain exists in arr, return
Note: Consider whether you can solve this in a single pass using
extra space.
Constraints:
arr.length
arr[i]