#K84087. Longest Platonic Range
Longest Platonic Range
Longest Platonic Range
You are given an integer n
and a list of integers representing the heights of hills. Your task is to find the length of the longest platonic range in the list.
A platonic range is defined as a contiguous subarray that consists of a strictly increasing sequence followed by a strictly decreasing sequence. Formally, a subarray from index l
to r
(with l < r
) is a platonic range if there exists an index i
(with l < i < r
) such that:
$a_l < a_{l+1} < \cdots < a_i$ and $a_i > a_{i+1} > \cdots > a_r$,
with the requirement that both the increasing and decreasing parts contain at least one element. If no such range exists, output 0
.
inputFormat
The input is read from standard input (stdin) and consists of:
- An integer
n
representing the number of hills. - A line containing
n
space-separated integers representing the heights of the hills.
For example: 10\n2 1 4 7 3 2 5 6 8 4
outputFormat
Output a single integer to standard output (stdout): the length of the longest platonic range. If none exists, output 0
.
10
2 1 4 7 3 2 5 6 8 4
5