C++ solution | O(n) | without using trie
The key idea is to get maximum number of set bits starting from the leftmost bit. I\'ve used mask to keep the prefix of every number.\n\nmask after each iterati
The key idea is to get maximum number of set bits starting from the leftmost bit. I\'ve used mask to keep the prefix of every number.\n\nmask after each iteration:\n```\n10000000000000000...\n11000000000000000...\n11100000000000000...\n11110000000000000...\n11111000000000000...\n11111100000000000...\n11111110000000000...\n....\n```\n\nbitwise and(&) of mask and array element gives the prefix. Prefix for all numbers of the array is stored in a set.\n\nXOR property used in the next step.\n```\nA ^ B = C\nA ^ C = B\n```\n\nmaxPossible = **max1 | (1<<i)** gives the maximum possible output we can get in i\'th iteration. Finally, if xor of any two elements in the set is equal to maxPossible, we update the max1 to maxPossible. The property mentioned above can be used to find if there\'s a pair in the set such that xor of the elements in the pair gives maxPossible.\n\n```\nsetElement1 ^ setElement2 = maxPossible\nsetElement1 ^ maxPossible = setElement2\n\ncode - \nfor(auto i : s){\n     if(s.find(i ^ possible) != s.end()){\n             max1 = possible;\n             break;\n\t}\n}\n```\n\n\n```\nclass Solution {\npublic:\n    int findMaximumXOR(vector<int>& nums) {\n        int n = nums.size();\n        int max1 = 0;\n        int mask = 0;\n        unordered_set<int> s;\n        \n        for(int i = 31; i>=0; i--){\n            mask |= (1<<i);\n            \n            for(int j = 0; j<n; j++){\n                s.insert(mask & nums[j]);\n            }\n            \n            int possible = max1 | (1<<i);\n            \n            for(auto j : s){\n                if(s.find(j ^ possible) != s.end()){\n                    max1 = possible;\n                    break;\n                }\n            }\n            \n            s.clear();\n        }\n        return max1;\n    }\n};\n```
[]