#C6835. Longest Mountain

    ID: 50639 Type: Default 1000ms 256MiB

Longest Mountain

Longest Mountain

You are given T test cases. In each test case, you have an array of integers representing heights. Your task is to find the length of the longest mountain in each array. A mountain is defined as a subarray that has:

  • A strictly increasing sequence followed immediately by a strictly decreasing sequence, with at least one element in each part.
  • The peak (the highest element) must be greater than its adjacent elements.

Formally, for a subarray A[i...j] to form a mountain, there must exist an index k (i < k < j) such that

\(A[i] < A[i+1] < \cdots < A[k]\) and \(A[k] > A[k+1] > \cdots > A[j]\).

If no valid mountain exists in a test case, output 0 for that case.

Note: Input is read from standard input and output is written to standard output.

inputFormat

The first line contains an integer T, the number of test cases.

For each test case:

  • The first line contains an integer N representing the number of elements in the array.
  • The second line contains N space-separated integers representing the heights.

All input is read from standard input.

outputFormat

For each test case, output a single line containing the length of the longest mountain found in the corresponding array. If no mountain exists, output 0.

Output is written to standard output.

## sample
3
9
2 1 4 7 3 2 5 2 1
5
2 2 2 2 2
7
2 3 3 2 1 0 1
5

0 0

</p>