Maximum XOR path of a Binary Tree | Binary tree node ; Function to create a new node ; Function calculate the value of max - xor ; Updating the xor value with the xor of the path from root to the node ; Check if node is leaf node ; Check if the left node exist in the tree ; Check if the right node exist in the tree ; Function to find the required count ; Recursively traverse the tree and compute the max_xor ; Return the result ; Create the binary tree
class Node : NEW_LINE INDENT def __init__ ( self , data ) : NEW_LINE INDENT self . data = data NEW_LINE self . left = None NEW_LINE self . right = None NEW_LINE DEDENT DEDENT def Solve ( root , xr , max_xor ) : NEW_LINE INDENT xr = xr ^ root . data NEW_LINE if ( root . left == None and root . right == None ) : NEW_LINE INDENT max_xor [ 0 ] = max ( max_xor [ 0 ] , xr ) NEW_LINE DEDENT if root . left != None : NEW_LINE INDENT Solve ( root . left , xr , max_xor ) NEW_LINE DEDENT if root . right != None : NEW_LINE INDENT Solve ( root . right , xr , max_xor ) NEW_LINE DEDENT return NEW_LINE DEDENT def findMaxXor ( root ) : NEW_LINE INDENT xr , max_xor = 0 , [ 0 ] NEW_LINE Solve ( root , xr , max_xor ) NEW_LINE return max_xor [ 0 ] NEW_LINE DEDENT root = Node ( 2 ) NEW_LINE root . left = Node ( 1 ) NEW_LINE root . right = Node ( 4 ) NEW_LINE root . left . left = Node ( 10 ) NEW_LINE root . left . right = Node ( 8 ) NEW_LINE root . right . left = Node ( 5 ) NEW_LINE root . right . right = Node ( 10 ) NEW_LINE print ( findMaxXor ( root ) ) NEW_LINE