Length of the longest subsequence such that XOR of adjacent elements is equal to K | ''Function to find maximum length of subsequence having XOR of adjacent elements equal to K ; '' Store maximum length of subsequence ; '' Stores the dp-states ; '' Base case ; '' Iterate over the range [1, N-1] ; '' Iterate over the range [0, i - 1] ; '' If arr[i]^arr[j] == K ; '' Update the dp[i] ; '' Update the maximum subsequence length ; '' If length of longest subsequence  is less than 2 then return 0 ; ''Driver Code ; '' Input ; '' Prthe length of longest subsequence
def xorSubsequence ( a , n , k ) : NEW_LINE INDENT ans = 0 ; NEW_LINE dp = [ 0 ] * n ; NEW_LINE dp [ 0 ] = 1 ; NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT for j in range ( i - 1 , - 1 , - 1 ) : NEW_LINE INDENT if ( ( a [ i ] ^ a [ j ] ) == k ) : NEW_LINE INDENT dp [ i ] = max ( dp [ i ] , dp [ j ] + 1 ) ; NEW_LINE DEDENT DEDENT ans = max ( ans , dp [ i ] ) ; NEW_LINE dp [ i ] = max ( 1 , dp [ i ] ) ; NEW_LINE DEDENT return ans if ans >= 2 else 0 ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 3 , 2 , 4 , 3 , 5 ] ; NEW_LINE K = 1 ; NEW_LINE N = len ( arr ) ; NEW_LINE print ( xorSubsequence ( arr , N , K ) ) ; NEW_LINE DEDENT