class
GFG {
static
class
Node {
int
data =
0
;
Node left =
null
, right =
null
;
};
static
Node newNode(
int
data) {
Node newNode =
new
Node();
newNode.data = data;
newNode.left = newNode.right =
null
;
return
(newNode);
}
static
int
Solve(Node root,
int
xr,
int
max_xor) {
xr = xr ^ root.data;
if
(root.left ==
null
&& root.right ==
null
) {
max_xor = Math.max(max_xor, xr);
return
max_xor;
}
if
(root.left !=
null
) {
max_xor = Solve(root.left, xr,
max_xor);
}
if
(root.right !=
null
) {
max_xor = Solve(root.right, xr,
max_xor);
}
return
max_xor;
}
static
int
findMaxXor(Node root) {
int
xr =
0
, max_xor =
0
;
max_xor = Solve(root, xr, max_xor);
return
max_xor;
}
public
static
void
main(String args[])
{
Node root = newNode(
2
);
root.left = newNode(
1
);
root.right = newNode(
4
);
root.left.left = newNode(
10
);
root.left.right = newNode(
8
);
root.right.left = newNode(
5
);
root.right.right = newNode(
10
);
System.out.print(findMaxXor(root));
}
}