Longest Zigzag Subsequence
A zigzag sequence strictly alternates between rising and falling steps. Print the length of the longest zigzag subsequence (not necessarily contiguous) of the array.
Input: the first line has N; the second line has N integers.
Output: the maximum zigzag subsequence length.
Constraints:
- 1 ≤ N ≤ 105
- −109 ≤ ai ≤ 109
Sample Tests
Input 1
6 1 7 4 9 2 5
Output 1
6
Input 2
4 3 3 3 3
Output 2
1
Discussion (opens after you solve — no spoilers before)
No comments yet.