#C8328. Longest Mountain Subarray
Longest Mountain Subarray
Longest Mountain Subarray
You are given an array of integers. Your task is to find the length of the longest mountain in the array.
A mountain is defined as a contiguous subarray that first strictly increases to a peak and then strictly decreases. Formally, a subarray \( A[l \dots r] \) (with \( r-l+1 \geq 3 \)) is called a mountain if there exists an index \( i \) such that \( l < i < r \) and:
- \( A[l] < A[l+1] < \cdots < A[i] \)
- \( A[i] > A[i+1] > \cdots > A[r] \)
If no mountain exists, output 0
.
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains a single integer \( n \) indicating the number of elements in the array.
- The second line contains \( n \) space-separated integers representing the elements of the array.
outputFormat
Output a single integer to standard output (stdout) indicating the length of the longest mountain found in the array. If no mountain exists, output 0
.
12
2 1 4 7 3 2 5 5 6 4 3 2
5