#K51872. Longest Mountain in an Array

    ID: 29184 Type: Default 1000ms 256MiB

Longest Mountain in an Array

Longest Mountain in an Array

You are given an array of positive integers. Your task is to find the length of the longest mountain in the array.

A mountain is defined as a subarray that:

  • Has at least 3 elements.
  • There exists some index i (0 < i < n-1) such that:
    • The elements from the beginning of the mountain to i (inclusive) are strictly increasing.
    • The elements from i to the end of the mountain are strictly decreasing.

If no mountain exists in the array, output 0.

Note that the mountain must have a peak and be strictly increasing before and strictly decreasing after the peak.

inputFormat

The first line of input contains a single integer N, the number of elements in the array. The second line contains N space-separated positive integers representing the array.

outputFormat

Output a single integer, the length of the longest mountain in the array. If no mountain exists, output 0.

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