one pass bitwise-2.
IntuitionApproachComplexity

Time complexity:
O(n)


Space complexity:
O(n)

Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
O(n)

- Space complexity:
O(n)

# Code
```cpp []
class Solution {
public:
    vector<int> minBitwiseArray(vector<int>& nums) {
        int n = nums.size();
        vector<int> ans;
        for (auto it : nums) {
            if (it == 2)
                ans.push_back(-1);
            else {
                int temp = it, val = 0;
                while (temp > 0) {
                    if (allSetBits(temp)) {
                        val += temp / 2;
                        temp = 0;
                    } else {
                        int x = largestPowerOfTwoLessThan(temp);
                        temp -= x;
                        val += x;
                    }
                }
                ans.push_back(val);
            }
        }
        return ans;
    }
    bool allSetBits(int n) { return ((n & (n + 1)) == 0); }
    int largestPowerOfTwoLessThan(int n) {
        if (n <= 1)
            return 0;
        int power = floor(log2(n));
        return 1 << power;
    }
};
```
['C++']