Problems > Longest Mountain

Longest Mountain

Difficulty: 1500 4000 ms 128 MB

two-pointers

A mountain is a contiguous stretch that strictly increases to a peak then strictly decreases, with length ≥ 3. Print the longest mountain's length (0 if none).

Input: the first line has N; the second line has N integers.

Output: the longest mountain length, or 0.

Constraints:

  • 1 ≤ N ≤ 105
  • |ai| ≤ 109

Sample Tests

Input 1
7
2 1 4 7 3 2 5
Output 1
5
Input 2
3
1 2 3
Output 2
0

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.