Java || Bit Manipulation + Trie || O(n)
\n    public class Trie {\n\n\t\tprivate class Node {\n\n\t\t\tint data;\n\t\t\tNode[] children;\n\n\t\t\tpublic Node(int data) {\n\t\t\t\tthis.data = data;\n\t
\n    public class Trie {\n\n\t\tprivate class Node {\n\n\t\t\tint data;\n\t\t\tNode[] children;\n\n\t\t\tpublic Node(int data) {\n\t\t\t\tthis.data = data;\n\t\t\t\tthis.children = new Node[2];\n\t\t\t}\n\n\t\t}\n\n\t\tprivate Node root;\n\n\t\t// O(1)\n\t\tpublic Trie() {\n\t\t\tthis.root = new Node(-1);\n\t\t}\n\n\t\t// O(32)\n\t\tpublic void addWord(int num) {\n\t\t\tNode curr = root;\n\t\t\tfor (int i = 30; i >= 0; i--) {\n\t\t\t\tint mask = 1 << i;\n\t\t\t\tint bit = num & mask;\n\t\t\t\tbit = (bit != 0) ? 1 : 0;\n\t\t\t\tNode temp = curr.children[bit];\n\t\t\t\tif (temp == null){\n\t\t\t\t\ttemp = new Node(bit);\n                    curr.children[bit] = temp;\n                }\n\t\t\t\tcurr = temp;\n\t\t\t}\n\t\t}\n\n\t\t// O(32)\n\t\tpublic int searchWord(int num) {\n\t\t\tNode curr = root;\n\t\t\tint ans = 0;\n\t\t\tfor (int i = 30; i >= 0; i--) {\n\t\t\t\tint mask = 1 << i;\n\t\t\t\tint bit = num & mask;\n\t\t\t\tbit = (bit != 0) ? 1 : 0;\n\t\t\t\tint toggle = bit ^ 1;\n\t\t\t\tNode temp = curr.children[toggle];\n\t\t\t\tif (temp != null) {\n\t\t\t\t\tcurr = temp;\n\t\t\t\t\tans |= mask;\n\t\t\t\t} else\n\t\t\t\t\tcurr = curr.children[bit];\n\t\t\t}\n\t\t\treturn ans;\n\t\t}\n\n\t}\n\n\t// O(n)\n\t// Trie\n\tpublic int findMaximumXOR(int[] nums) {\n\n\t\tTrie trie = new Trie();\n\t\tint max = 0;\n\t\tfor (int num : nums)\n\t\t\ttrie.addWord(num);\n        \n\t\tfor (int num : nums) {\n\t\t\tint ans = trie.searchWord(num);\n\t\t\tmax = Math.max(ans, max);\n\t\t}\n\n\t\treturn max;\n\t}\n
[]