Length of longest increasing absolute even subsequence | C # program for the above approach ; Function to find the longest increasing absolute even subsequence ; Length of arr ; Stores length of required subsequence ; Traverse the array ; Traverse prefix of current array element ; Check if the subsequence is LIS and have even absolute difference of adjacent pairs ; Update lis [ ] ; Stores maximum length ; Find the length of longest absolute even subsequence ; Return the maximum length of absolute even subsequence ; Driver code ; Given array [ ] arr and brr [ ] ; Function call
using System ; class GFG { static void EvenLIS ( int [ ] arr ) { int n = arr . Length ; int [ ] lis = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) lis [ i ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 0 ; j < i ; j ++ ) { if ( Math . Abs ( arr [ i ] ) > Math . Abs ( arr [ j ] ) && Math . Abs ( arr [ i ] ) % 2 == 0 && Math . Abs ( arr [ j ] ) % 2 == 0 && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ; } } int maxlen = 0 ; for ( int i = 0 ; i < n ; i ++ ) maxlen = Math . Max ( maxlen , lis [ i ] ) ; Console . WriteLine ( maxlen ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 11 , - 22 , 43 , - 54 , 66 , 5 } ; int N = arr . Length ; EvenLIS ( arr ) ; } }