O(32N) PrefixBit
IntuitionWant: ans[i] OR (ans[i] + 1) == nums[i]Prime means all odd, except 2
So at least (p-1)|p==p (trivial root)We brute force all possible prefix|prefix-1 a
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Want: ans[i] OR (ans[i] + 1) == nums[i]

Prime means all odd, except 2
So at least (p-1)|p==p (trivial root)

We brute force all possible prefix|prefix-1 and return the smallest

        101101
        prefix|(prefix-1)
        100000|011111   smallest prefix
        101000|100111
        101100|101011   
        101101|101100   largest prefix (trivial match)

TC: O(NlogMAX) = O(32N)



# Code
```python3 []
class Solution:
    def minBitwiseArray(self, nums: List[int]) -> List[int]:
        N=len(nums)
        ans=[]
        B=32
        def get(i):#get smallest j s.t. j|j+1==i
            prefix = 0
            for b in range(B-1,-1,-1):
                prefix|= i&(1<<b)
                if prefix>0 and prefix|(prefix-1)==i:
                    return prefix-1
            return -1

        for i in range(N):
            ans.append(get(nums[i]))
        return ans


```
['Bit Manipulation', 'Prefix Sum', 'Python3']