Given an array A of N positive integers. The task is to find the longest Zig-Zag subsequence problem such that all elements of this are alternating (Ai-1 < Ai > Ai+1).
The first line of input contains an integer T denoting the number of test cases. Each test case contains an integer N which denotes the number of elements in the array A. Next line contains space separated n elements in the array A.
Print the length of the longest such subsequence.
1 <= T <= 200
1 <= N <= 103
1 <= Ai <= 105
5 5 10 100 10 5
1 2 3
Testcase 1: 5, 10, 5 is the longest common subsequence with elements alternating.
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.