Length of longest increasing absolute even subsequence | 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 ; Given arr [ ] ; Function Call
def EvenLIS ( arr ) : NEW_LINE INDENT n = len ( arr ) NEW_LINE lis = [ 1 ] * n NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT for j in range ( 0 , i ) : NEW_LINE INDENT if abs ( arr [ i ] ) > abs ( arr [ j ] ) and abs ( arr [ i ] % 2 ) == 0 and abs ( arr [ j ] % 2 ) == 0 and lis [ i ] < lis [ j ] + 1 : NEW_LINE INDENT lis [ i ] = lis [ j ] + 1 NEW_LINE DEDENT DEDENT DEDENT maxlen = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT maxlen = max ( maxlen , lis [ i ] ) NEW_LINE DEDENT print ( maxlen ) NEW_LINE DEDENT arr = [ 11 , - 22 , 43 , - 54 , 66 , 5 ] NEW_LINE EvenLIS ( arr ) NEW_LINE