#K84402. Pyramid Array Verification
Pyramid Array Verification
Pyramid Array Verification
Given an array of positive integers, determine whether it forms a pyramid array. A pyramid array is defined such that it starts at 1 and increases by 1 consecutively until it reaches a peak, then decreases by 1 consecutively until it returns to 1. Formally, if the array is denoted as \(a_1, a_2, \dots, a_n\), there exists an index \(k\) with \(1 < k < n\) such that:
\(a_1 = 1,\, a_{i} = a_{i-1}+1 \) for \(2 \le i \le k\) and \(a_{j} = a_{j-1}-1\) for \(k+1 \le j \le n\).
The array must contain at least three elements and the peak (maximum element) cannot be the first or the last element.
inputFormat
The first line contains a single integer (n), denoting the number of elements in the array. The second line contains (n) space-separated positive integers.
outputFormat
Output a single integer: 1 if the array is a pyramid array; otherwise, output 0.## sample
9
1 2 3 4 5 4 3 2 1
1