#C10955. Longest Mountain in Array
Longest Mountain in Array
Longest Mountain in Array
A mountain in an array is defined as a contiguous subarray that first strictly increases to a peak and then strictly decreases. More formally, a subarray A[l...r] (with r - l + 1 ≥ 3) is a mountain if there exists an index i (l < i < r) such that:
\(A[l] < A[l+1] < \cdots A[i+1] > \cdots > A[r]\).
If no mountain exists in the array, the answer is 0.
Input/Output:
You are given an integer \(n\) followed by \(n\) integers. Find and output the length of the longest mountain in the array. The answer must be output as a single integer to stdout.
Example:
Input:
7
2 1 4 7 3 2 5
Output:
5
Note: The problem requires the use of LaTeX for mathematical formulas as shown above.
inputFormat
The first line of input contains a single integer (n) (0 ≤ n ≤ 10^5) denoting the number of elements in the array. The second line contains (n) space-separated integers.
outputFormat
Output a single integer which is the length of the longest mountain in the array. If there is no mountain, output 0.## sample
7
2 1 4 7 3 2 5
5