Detailed explanation with tries
This problem can be solved by help to trie(prefix tree). \n\nApproach: -\n1.  XOR table \n\n\n\n\nAs shown in above table xor gives maximum number when its xore
This problem can be solved by help to trie(prefix tree). \n\nApproach: -\n**1.  XOR table **\n\n![image](https://assets.leetcode.com/users/images/3ca6d92b-1ddf-4387-a974-cfa752dc487d_1619167885.3818417.jpeg)\n\n\nAs shown in above table xor gives maximum number when its xored with its complement. we will make use of this logic while solving the problem. \n\n**2.  Create binary trie **\n\nwe will xor th current element with all its previous elements and store the result which gives maximum xor.\n\n![image](https://assets.leetcode.com/users/images/88c21dc5-098a-48cf-9781-a0e089d33e7c_1619166744.6285884.jpeg)\n\nabove image shows binary representation of all input numbers \n\nnow we will create binary tree for 3, 10 and 5 repsectively (we will take 5 bit implementation for working) and see how the logic will work.  \n\n![image](https://assets.leetcode.com/users/images/f5cee1d2-3652-466a-a76e-60dce72dcf85_1619167562.4124656.jpeg)\n\nAs show in the above diagrams we will create the binary trie for 2 when we want to operate for second number i.e 10 then we will go in the direction of its complement. As you can see in the second digram in the above image when we want to operate third number i.e 5 we will traverse in the binary tries of 3 and 10 but in the direction of its complement. \n\n**working code**\n\n```\n\nclass TrieNode:\n    def __init__(self):\n        self.children = defaultdict(TrieNode)\n        self.val = 0\n\nclass Trie:\n    def __init__(self):\n        self.root = TrieNode()\n\n    def insert(self, binary_str, num):\n        curr = self.root\n\n        for bit in binary_str:\n            curr = curr.children[int(bit)]\n\n        curr.val = num\n\n    def seacrh(self, binary, num):\n        curr = self.root\n        for bit in binary:\n            d = int(bit)\n            want = d ^ 1\n            if want in curr.children:\n                curr = curr.children[want]\n            else:\n                curr = curr.children[want ^ 1]\n\n        return curr.val ^ num\n\n\nclass Solution(object):\n    def findMaximumXOR(self, nums):\n        """\n        :type nums: List[int]\n        :rtype: int\n        """\n        trie = Trie()\n        max_xor = float("-inf")\n\n        for num in nums:\n            binary_str = bin(num)[2:].zfill(32)\n            trie.insert(binary_str, num)\n\n            max_xor = max(max_xor, trie.seacrh(binary_str, num))\n\n        return max_xor\n\ns = Solution()\nprint s.findMaximumXOR([3,10,5,25,2,8])\n```\n\n\nThank You.\nHappy Coding \n\n
[]