#K52182. Longest Peak

    ID: 29253 Type: Default 1000ms 256MiB

Longest Peak

Longest Peak

You are given an array of integers. Your task is to find the length of the longest peak in the array. A peak is defined as a contiguous subarray \(A[i \ldots j]\) that satisfies:

  • There exists some index \(k\) with \(i < k < j\) such that
  • \(A[i] < A[i+1] < \cdots < A[k]\)
  • \(A[k] > A[k+1] > \cdots > A[j]\)

The peak must have a minimum length of 3. If no such peak exists, output 0.

Example:

Input: [1, 3, 2, 4, 5, 3, 2, 8, 6, 5]
Output: 5

inputFormat

The first line contains an integer \(T\), denoting the number of test cases.

For each test case, the first line contains an integer \(n\) — the number of elements in the array, followed by a line with \(n\) space-separated integers representing the elements of the array.

All input is given via stdin.

outputFormat

For each test case, output a single integer representing the length of the longest peak in the array on a separate line.

All output should be written to stdout.

## sample
3
10
1 3 2 4 5 3 2 8 6 5
7
2 1 4 7 3 2 5
5
1 2 3 4 5
5

5 0

</p>