C++ solution without tries (using bitmasking & set)
Intuition\n- The problem requires finding the maximum XOR value that can be obtained by selecting two numbers from the given array. We need to iteratively build
# Intuition\n- The problem requires finding the maximum XOR value that can be obtained by selecting two numbers from the given array. We need to iteratively build the XOR result from the most significant bit to the least significant bit.\n\n# Approach\n1. Initialize the `mask` and `ans` variables to 0. `mask` will be used to iteratively build the XOR result, and `ans` will store the maximum XOR value.\n2. Start iterating from the 31st bit (most significant bit) down to the 0th bit (least significant bit).\n3. At each iteration, set the corresponding bit in the `mask` to 1 using bitwise OR (`mask |= 1<<i`).\n4. Create an unordered set `myset` to store the prefixes of numbers obtained by applying the current `mask` to each number in the array.\n5. Iterate through each number in the array (`num`) and insert `mask & num` into the `myset`.\n6. Calculate a `temp` value by setting the current bit in `ans` to 1 using bitwise OR (`temp = ans | (1<<i)`).\n7. Iterate through each prefix in the `myset` and check if `temp ^ prefix` exists in the `myset`. If found, update `ans` to `temp`.\n8. Repeat the above steps for all bits from 31 to 0.\n9. Return the final `ans` which represents the maximum XOR value that can be obtained.\n\n# Complexity\n- Time complexity: $$O(32 * n)$$, where n is the number of elements in the array. We iterate through each bit position 32 times and perform set insertions and searches.\n- Space complexity: $$O(n)$$, for the unordered set `myset` which can store up to n elements.\n\n# Code\n```\nclass Solution {\npublic:\n    int findMaximumXOR(vector<int>& nums) {\n        int mask = 0, ans = 0;\n        for (int i=31; i>=0; i--) {\n            mask |= 1<<i;\n            unordered_set<int> myset;\n            for (int num: nums) myset.insert(mask & num);\n            int temp = ans | (1<<i);\n            for (int prefix: myset) {\n                if (myset.find(temp ^ prefix) != myset.end()) {\n                    ans = temp; break;\n                }\n            }\n        }\n        return ans;\n    }\n};\n```
['Bit Manipulation', 'C++']