Explanation | Trie | Approach
TC -- O(N)\nSC -- O(1)  //32 is constant\n\n#### Approach :- Here, we are creating Trie of 1/0 representing all numbers by consuming less space and efficient se
**TC -- O(N)\nSC -- O(1)  //32 is constant**\n\n#### Approach :- Here, we are creating Trie of 1/0 representing all numbers by consuming less space and efficient searching. When we have 0 bit in our hand we are looking for 1 bit greddily to make maximum XOR and vice-versa.\n# \n\n```\nclass TrieNode {\npublic:\n\tTrieNode *left;\n\tTrieNode *right;\n};\n\nvoid insertNode(int n, TrieNode *head) {\n\tTrieNode *curr = head;\n\tfor (int i = 31; i >= 0; i--) {\n\n\t\tint bit = (n >> i) & 1;\n\n\t\tif (bit == 0) {\n\t\t\tif (!curr->left) {\n\t\t\t\tcurr->left = new TrieNode();\n\t\t\t}\n\t\t\tcurr = curr->left;\n\t\t}\n\n\t\telse {\n\t\t\tif (!curr->right) {\n\t\t\t\tcurr->right = new TrieNode();\n\t\t\t}\n\t\t\tcurr = curr->right;\n\t\t}\n\n\t}\n}\n\nclass Solution {\npublic:\n\tint findMaximumXORHelper(vector<int>& nums, TrieNode *head, int size) {\n\t\tint maXOR = INT_MIN;\n\n\t\tfor (int i = 0; i < size; i++) {\n\t\t\tint value = nums[i];\n\t\t\tTrieNode *curr = head;\n\t\t\tint currXOR = 0;\n\n\t\t\tfor (int j = 31; j >= 0; j--) {\n\n\t\t\t\tint bit = (value >> j) & 1;\n\n\t\t\t\tif (bit == 0) {\n\t\t\t\t\tif (curr->right) {\n\t\t\t\t\t\tcurrXOR += 1 << j;\n\t\t\t\t\t\tcurr = curr->right;\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tcurr = curr->left;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\telse {\n\t\t\t\t\tif (curr->left) {\n\t\t\t\t\t\tcurrXOR += 1 << j;\n\t\t\t\t\t\tcurr = curr->left;\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tcurr = curr->right;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t\tmaXOR = max(maXOR, currXOR);\n\t\t}\n\t\treturn maXOR;\n\t}\n\n\tint findMaximumXOR(vector<int>& nums) {\n\t\tTrieNode *head = new TrieNode();\n\t\tfor (int i = 0; i < nums.size(); i++) {\n\t\t\tinsertNode(nums[i], head);\n\t\t}\n\n\t\treturn findMaximumXORHelper(nums, head, nums.size());\n\t}\n};\n```\n***Hope this helped you, use comment if you have any doubt...***\n**For more deatil :-** [Maximum XOR of Two Numbers in an Array](https://www.youtube.com/watch?v=wSgrc98d2lI)
['Trie']