#K84177. Pyramid Blocks
Pyramid Blocks
Pyramid Blocks
Given an array of integers representing the heights of blocks, determine whether these blocks can form a pyramid-like structure. A pyramid-like structure is defined as a sequence that strictly increases to a single peak and then strictly decreases. In other words, there must exist an index (i) (with (1 < i < n)) such that (a_1 < a_2 < \cdots < a_i) and (a_i > a_{i+1} > \cdots > a_n). The sequence must contain at least three elements since the pyramid requires both an increasing and a decreasing part.
For example:
[1, 2, 3, 4, 3, 2, 1]
forms a pyramid and should outputTrue
.[1, 3, 2]
forms a pyramid and should outputTrue
.[1, 2, 3]
does not form a pyramid and should outputFalse
.
inputFormat
The first line contains an integer (n) (the number of blocks). The second line contains (n) space-separated integers (a_1, a_2, \ldots, a_n) representing the heights of the blocks.
outputFormat
Output a single line containing either True
if the blocks can form a pyramid-like structure, or False
otherwise.## sample
7
1 2 3 4 3 2 1
True