#C561. Longest Mountain in Array

    ID: 49278 Type: Default 1000ms 256MiB

Longest Mountain in Array

Longest Mountain in Array

Given an array of integers representing heights, a mountain is defined as a contiguous subarray where the elements strictly increase to a peak and then strictly decrease. The minimum length of a mountain is 3.

Formally, for an array \( A = [a_0, a_1, \dots, a_{n-1}] \), a mountain is a subarray \( A[l \dots r] \) (with \( r - l + 1 \ge 3 \)) such that there exists an index \( i \) with \( l < i < r \) satisfying:

\[ \begin{aligned} a_{l} &< a_{l+1} < \cdots a_{i+1} > \cdots > a_{r}. \end{aligned} \]

Your task is to compute the length of the longest mountain in the given array. If no mountain exists, output 0.

inputFormat

The input is read from standard input (stdin). It begins with an integer \( T \) representing the number of test cases. Each test case consists of two lines:

  • The first line contains an integer \( N \), the size of the array.
  • The second line contains \( N \) space-separated integers representing the array elements.

outputFormat

For each test case, output a single integer on a new line indicating the length of the longest mountain in the array. If no mountain exists, output 0.

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

0 0 3 5

</p>