#K34592. Counting Mountains in an Array
Counting Mountains in an Array
Counting Mountains in an Array
You are given an array of n integers. Your task is to count the number of mountains in the array. A mountain is defined as a contiguous subsequence of at least three elements that first strictly increases to a peak and then strictly decreases. Formally, a mountain is a subarray A[l...r] (with r - l + 1 ≥ 3) for which there exists an index i with l < i < r satisfying:
$$A[l] < A[l+1] < \cdots < A[i] \quad\text{and}\quad A[i] > A[i+1] > \cdots > A[r]$$
Your program should read the input from stdin
and output the result to stdout
.
inputFormat
The first line of input contains a single integer n (the length of the array). The second line contains n space-separated integers representing the elements of the array.
Example:
5 2 3 4 3 2
outputFormat
Output a single integer representing the number of mountains in the array.
Example:
1## sample
5
2 3 4 3 2
1
</p>