#K15181. Longest Mountain Subarray
Longest Mountain Subarray
Longest Mountain Subarray
In this problem, you are given an array of integers and your task is to find the length of the longest subarray which forms a mountain. A mountain subarray is defined as a contiguous subarray that has a strictly increasing sequence followed by a strictly decreasing sequence, and it must contain at least three elements. More formally, a subarray a[l...r] (with r - l + 1 ≥ 3) is considered a mountain if there exists an index p (l < p < r) such that:
If no such mountain exists, output 0. The input is read from standard input and the result should be printed to standard output.
inputFormat
The input is given via standard input. The first line contains a single integer n (the length of the array). The second line contains n space-separated integers representing the array.
outputFormat
Output a single integer representing the length of the longest mountain subarray. If no mountain exists, output 0.## sample
9
2 1 4 7 3 2 5 6 7
5