#K44522. Longest Non-decreasing Growth Period
Longest Non-decreasing Growth Period
Longest Non-decreasing Growth Period
You are given a sequence of integer height measurements. Your task is to determine the length of the longest continuous segment in which the measurements never decrease. Formally, for a sequence \(a_1, a_2, \dots, a_n\), you need to find the maximum length \(l\) such that for some index \(i\) (with \(1 \le i \le n-l+1\)) and for all \(j\) from 1 to \(l-1\), the condition \(a_{i+j-1} \le a_{i+j}\) holds.
Example:
Input: 7 1 2 2 1 3 4 1 Output: 3
In the above example, the longest continuous non-decreasing subarray is [1, 3, 4] which has a length of 3.
inputFormat
The first line of input contains an integer \(T\) representing the number of test cases. Each test case consists of two lines:
- The first line contains an integer \(N\), the number of height measurements.
- The second line contains \(N\) space-separated integers representing the height measurements.
The input is given via stdin.
outputFormat
For each test case, output the length of the longest continuous segment where the height measurements are non-decreasing. Each result should be printed on a separate line to stdout.
## sample3
7
1 2 2 1 3 4 1
5
5 5 5 5 5
6
1 3 2 2 2 3
3
5
4
</p>