#K58592. Largest Plateau
Largest Plateau
Largest Plateau
You are given a sequence of blocks with specific heights. Your task is to find the largest plateau in the sequence. A plateau is defined as a contiguous segment of blocks that all have the same height and must contain at least two blocks. If there are several plateaus of the same maximum length, select the one that appears first in the sequence.
If a valid plateau exists, output the starting position (using 1-indexing) and the length of the plateau; otherwise, output 0
.
The solution requires processing input from stdin
and printing the result to stdout
.
Note: In mathematical terms, if the input heights array is \( h_1, h_2, \ldots, h_n \), find the maximum integer \( L \) and index \( i \) such that \( h_i = h_{i+1} = \cdots = h_{i+L-1} \) with \( L \ge 2 \). If no such \( L \) exists, output \(0\).
inputFormat
The first line contains a single integer \( n \) denoting the number of blocks. The second line contains \( n \) space-separated integers representing the heights of the blocks.
Example:
7 2 2 3 3 3 4 4
outputFormat
If a plateau is found, output two space-separated integers: the starting index (1-indexed) and the length of the plateau. If no plateau exists, output 0
.
Example:
3 3## sample
7
2 2 3 3 3 4 4
3 3