Length of longest subsequence whose XOR value is odd | Function for find max XOR subsequence having odd value ; Initialize odd and even count ; Count the number of odd and even numbers in given array ; If all values are odd in given array ; If all values are even in given array ; If both odd and even are present in given array ; Driver code ; Given array arr [ ] ; Function Call
def maxXorSubsequence ( arr , n ) : NEW_LINE INDENT odd = 0 NEW_LINE even = 0 NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT if arr [ i ] % 2 != 0 : NEW_LINE INDENT odd += 1 NEW_LINE DEDENT else : NEW_LINE INDENT even += 1 NEW_LINE DEDENT DEDENT if odd == n : NEW_LINE INDENT if odd % 2 == 0 : NEW_LINE INDENT maxlen = n - 1 NEW_LINE DEDENT else : NEW_LINE INDENT maxlen = n NEW_LINE DEDENT DEDENT elif even == n : NEW_LINE INDENT maxlen = 0 NEW_LINE DEDENT else : NEW_LINE INDENT if odd % 2 == 0 : NEW_LINE INDENT maxlen = even + odd - 1 NEW_LINE DEDENT else : NEW_LINE INDENT maxlen = even + odd NEW_LINE DEDENT DEDENT return maxlen NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 2 , 3 , 4 , 5 , 6 , 7 ] NEW_LINE n = len ( arr ) NEW_LINE print ( maxXorSubsequence ( arr , n ) ) NEW_LINE DEDENT