Sequence
InterviewTime limit1sMemory limit128 MB
Find the maximum length of a contiguous subarray of digits that is either nondecreasing or nonincreasing.
- Level
Easy3 of 10
- Topics
- Array, Dynamic programming, Implementation
- Solved
- No attempts yet
Problem
You are given a sequence of length N made of digits from 0 to 9. Consider contiguous segments that, from left to right, are either nondecreasing or nonincreasing.
Print the maximum possible length of such a segment. Equal adjacent digits satisfy both direction conditions.
Input
The first line contains the length N of the sequence.
The second line contains N digits separated by spaces.
N is an integer between 1 and 100,000, inclusive.
Output
Print the length of the longest contiguous segment that is nondecreasing or nonincreasing.