#C283. Longest Mountain in Array

    ID: 46189 Type: Default 1000ms 256MiB

Longest Mountain in Array

Longest Mountain in Array

You are given an array of integers. A mountain is defined as a subarray that:

  • Has a length of at least 3.
  • There exists some index i (0 < i < length-1) such that:
    • The subarray strictly increases from the beginning to i, and
    • Then strictly decreases from i to the end.

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

Note: A mountain must have at least one element on each side of the peak.

inputFormat

The input is read from standard input (stdin).\nThe first line contains an integer n representing the number of elements in the array.\nThe second line contains n space separated integers representing the array.

outputFormat

Output a single integer to standard output (stdout), indicating the length of the longest mountain in the array. If there is no mountain, output 0.## sample

7
2 1 4 7 3 2 5
5