C++ || Commented ||
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $O(32*n)$\n\n- Space complexity: $O(n)$ for storing result\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    vector<int> minBitwiseArray(vector<int>& nums) {\n        int n = nums.size(); // Get the size of the input array\n        vector<int> result; // Initialize a vector to store the results\n\n        // Iterate over each number in the input array\n        for(auto num : nums) {\n            // If the number is 2, add -1 to the result vector\n            if(num == 2) \n                result.push_back(-1);\n            else {\n                // Try to find the first bit that is not set (0) in the number\n                for(int i = 0; i <= 31; i++) {\n                    // Check if the bit at position i is 0\n                    if((num & (1 << i)) == 0) {\n                        // Flip the bit at position i-1\n                        num = num ^ (1 << (i-1));\n                        // Add the modified number to the result vector\n                        result.push_back(num);\n                        // Break the loop after modifying the number\n                        break;\n                    }\n                }\n            }\n        }\n\n        // Return the resulting vector\n        return result;\n    }\n};\n```
['Math', 'Bit Manipulation', 'C++']