Maximum XOR | Python3 using tries
\nclass Solution:\n    def findMaximumXOR(self, nums: List[int]) -> int:\n        bin_list = ["{0:b}".format(el) for el in nums]\n        max_len = len(max(bin_
```\nclass Solution:\n    def findMaximumXOR(self, nums: List[int]) -> int:\n        bin_list = ["{0:b}".format(el) for el in nums]\n        max_len = len(max(bin_list, key = lambda x: len(x)))\n        bin_list = ["0"*(max_len - len(el)) + el for el in bin_list]\n        ans = float(\'-inf\')\n        # create a trie and for each representation try to find the exact opposite as much as possible\n        trie = {}\n        for word in bin_list:\n            parent = trie\n            for char in (word):\n                if char in parent:\n                    parent = parent[char]\n                else:\n                    parent[char] = {}\n                    parent = parent[char]\n        # now for each item in binary_list, try to find the opposite\n        ans = float(\'-inf\')\n        for word in bin_list:\n            parent = trie\n            curr = \'\'\n            for idx, char in enumerate(word):\n                to_find = \'1\' if char == \'0\' else \'0\'\n                if to_find in parent:\n                    curr += to_find\n                    parent = parent[to_find]\n                else:\n                    curr += char\n                    parent = parent[char]\n                if idx == len(word) - 1:\n                    ans = max(ans, int(word, 2) ^ int(curr, 2) )\n        return ans  \n```
[]