Longest Increasing Odd Even Subsequence
Given a sequence of numbers you have to find out the length of the longest increasing odd even subsequence and print the length of the subsequence. The sequence will be maintaining like, (odd ) -> ( even ) -> ( odd ) -> ( even ) or (even ) -> ( odd ) -> ( even ) -> ( odd ) .
Input:
T Test case
T no. of input array along with their element no. N
E.g.
3
8
2 3 4 8 2 5 6 8
8
2 3 4 8 2 6 5 4
7
6 5 9 2 10 77 5
Constrain:
1≤ T ≤ 20
1≤ N ≤50
1≤ A[i] ≤50
Output:
Print the length of the longest increasing
odd even subsequence
Example
T=3
Input:
8
2 3 4 8 2 5 6 8
Output:
5 ( 2 3 4 5 8 )
Input:
8
2 3 4 8 2 6 5 4
Output:
4 ( 2 3 4 5 )
Input:
7
6 5 9 2 10 77 5
Output:
4 (6 9 10 77 )
Let N be the number of elements say, X1, X2, X3 ... Xn.
Let odd(a) = the value at the index a of the odd array and even(a) = the value at the index a of the even array.
To find the length of the longest increasing odd even subsequence we will follow these steps,
odd (index of current element) = even (index of the comparing element) + 1 ;
even (index of current element) = odd (index of the comparing element) + 1;
C++ Implementation:
Output
need an explanation for this answer? contact us directly to get an explanation for this answer