#C9457. Longest Monotonic Subarray
Longest Monotonic Subarray
Longest Monotonic Subarray
You are given several test cases. In each test case, the first number is an integer (N) representing the number of elements in the array, followed by (N) space-separated integers. Your task is to determine the length of the longest contiguous subarray that is either non-decreasing or non-increasing.
A subarray is defined as a contiguous sequence of elements. The answer for each test case should be printed on a separate line.
For example, given the array [1, 2, 4, 3, 5] (with (N=5)), the longest subarray that is monotonic (either non-decreasing or non-increasing) is either [1,2,4] (non-decreasing) or [4,3] (non-increasing), and the longest length is 3.
Note: When writing formulas in this statement, we use LaTeX format. For instance, the number of elements is denoted as (N).
inputFormat
The input is read from standard input (stdin). The first line contains one integer (T), the number of test cases. Each of the next (T) lines describes a test case. Each test case starts with an integer (N) followed by (N) space-separated integers.
outputFormat
For each test case, output a single line containing the length of the longest contiguous subarray that is either non-decreasing or non-increasing.## sample
1
1 5
1
</p>