4
// trie with max 2 child, not taking any bool or 26 size value because no9
void insert(TrieNode *root, int n) {10
TrieNode *curr = root;11
for (int i = 31; i >= 0; i--) {12
int bit = (n >> i) & 1; // it will find 31st bit and check it is 1 or 014
if (curr->zero == nullptr) { // if 0 then we will continue filling on zero side15
TrieNode *newNode = new TrieNode();18
curr = curr->zero; // increase cur to next zero position20
// similarly if we get 121
if (curr->one == nullptr) {22
TrieNode *newNode = new TrieNode();29
int findmax(TrieNode *root, int n) {30
TrieNode *curr = root;32
for (int i = 31; i >= 0; i--) {33
int bit = (n >> i) & 1;35
if (curr->zero != nullptr) { // finding complement , if find 1 then we36
// will check on zero side37
ans += (1 << i); // push values in ans40
curr = curr->one; // if we don't get then go to one's side43
// similarly on zero side if we get 0 then we will check on 1 s side44
if (curr->one != nullptr) {55
int findMaximumXOR(vector<int> &nums) {57
TrieNode *root = new TrieNode();59
for (int i = 0; i < n; i++) {60
insert(root, nums[i]); // it will make trie by inserting values62
for (int i = 1; i < n; i++) {63
ans = max(ans, findmax(root, nums[i])); // find the necessary complementory64
// values and maximum store