💡Efficient Java Solution | O(n) time complexity | 100% Beat 💡
Intuition
Prime Numbers:

The list nums contains prime numbers. All primes except 2 are odd numbers, and the only even prime number is 2.
This observation is cr
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

1. Prime Numbers:

- The list nums contains prime numbers. All primes except 2 are odd numbers, and the only even prime number is 2.
- This observation is critical because prime numbers, when written in binary, follow certain patterns.
2. Prime Numbers with All 1s in Binary:

- There is a special category of prime numbers that, when written in binary, consist entirely of 1s.
- Examples of such numbers include 3 (binary 11), 7 (binary 111), 31 (binary 11111), etc.
- These numbers are always of the form 2^k - 1 (i.e., one less than a power of 2).
3. Prime Numbers with Mixed Bits:

- Not all prime numbers are of the form 2^k - 1. Some prime numbers have a binary representation with at least one 0 bit.
- For example, 13 (binary 1101), 11 (binary 1011), etc., are prime but do not consist entirely of 1s in their binary form.

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

1. Handle Special Case for 2:

- If the number is 2, it is treated as a special case and can be skipped or handled separately (since it's the only even prime).
2. For Each Prime Number:

- Check if the number is of the form 2^k - 1:
    - If so, reset the MSB (i.e., halve the number).
- For Other Numbers:
    - Loop through the bits and find the next smallest valid number by resetting bits from LSB to MSB.
    - Ensure that after resetting a bit, the condition temp1 | (temp1 + 1) == temp is satisfied.
3. Store the Result and move to the next number.


# Complexity
- Time complexity: O(n * 32)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(n)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {
    public int[] minBitwiseArray(List<Integer> nums) {
        int [] ans= new int[nums.size()];
        Arrays.fill(ans,-1);
        for(int i=0;i<ans.length;i++){
            int temp=nums.get(i);
            int min=Integer.MAX_VALUE;
            if( ((temp+1)& temp)!=0){
            for(int j=0;j<32;j++){
                if((temp & (1<<j))!=0){
                    int temp1=(temp & ~(1<<j));
                    if((temp1 | (temp1+1)) == temp){
                        min=Math.min(min,temp1);
                    }
                }
            }
            if(min != Integer.MAX_VALUE )
                ans[i]=min;
            }
            else{
                int n= temp;
                int position=-1;
                while(n>0){
                    position++;
                    n=n>>1;
                }
                ans[i]= (temp & ~(1<< (position)));
            } 
        }
        return ans;
    }
}
```
['Array', 'Bit Manipulation', 'Java']