Recycled Problem
InterviewTime limit2sMemory limit1024 MB
Given a sequence, find the length of the longest contiguous subsequence that strictly increases then strictly decreases.
- Level
Medium4 of 10
- Topics
- Array, Implementation, Two pointers, Brute force
- Solved
- No attempts yet
Problem
The deadline for submitting problems for the finals of the 5th Cheonhajeil Coding Contest is one week away, but Jeonghwi has not even finished half of his problems. With the deadline closing in, he decides to recycle a problem from the preliminaries.
Specifically, he will combine the problems "Standing Tall on the High Namsan" and "Stand on the Foundation Stone" into a new problem.
A sequence of length is a mountain if it increases up to some point and decreases after that point.
In other words, there is an index such that for every with , and for every with .
Note that a sequence of length 1 is always a mountain.
Jeonghwi loves hiking, and he wants to find the length of the longest mountain among the contiguous subsequences of the sequence .
A contiguous subsequence is a sequence formed by choosing two indices with .
Write a program that finds the length of the longest mountain so that Jeonghwi can hike as much as he wants.
Input
The first line gives the length of the sequence, .
The second line gives integers separated by spaces.
Output
Print the length of the longest mountain among the contiguous subsequences of the sequence .
Constraints
Hint
The contest was postponed by one month, and Jeonghwi was happy about it.