Leetcode Problem 2479. Maximum XOR of Two Non-Overlapping Subtrees
2479. Maximum XOR of Two Non-Overlapping Subtrees
Leetcode Solutions
Using DFS and Trie for Maximum XOR of Two Subtrees
Create a graph representation of the tree using adjacency lists.
Perform a DFS to compute the sum of values for each subtree.
Initialize a Trie data structure for bitwise operations.
Perform a second DFS to find the maximum XOR of two non-overlapping subtrees:
a. Before traversing the children of the current node, calculate the maximum XOR of the current subtree sum with the sums in the Trie.
b. Traverse the children and repeat the process for each subtree.
c. After traversing the children, insert the current subtree sum into the Trie.
Return the maximum XOR value found during the second DFS.