100% Python 1 line solution Bit manipulation
\n\n# Intuition\nPerforming a bitwise OR with n and n+1 will fill the leftmost 0 in n. Therefore to get the lowest value of n where n OR (n+1) == v, we can repl
![image.png](https://assets.leetcode.com/users/images/3d4f0f11-941b-46f4-95bb-e07fe5149427_1729518278.1252615.png)\n\n# Intuition\nPerforming a bitwise OR with `n` and `n+1` will fill the leftmost `0` in `n`. Therefore to get the lowest value of `n` where `n OR (n+1) == v`, we can replace the highest consecutive `1` in `v` with a `0`. \n\nThe consecutive part refers to the unbroken stream of `1`\'s starting from the Least Significant Bit. For `7 == 0b0111` this would be the `1` next to the `0`, aka the second digit, or the value representing `4`. For `23 == 0b10111` the highest consecutive `1` is in the third position, again representing `4`.\n\nIf we replaced a higher, non-consecutive 1, then the addition of `n` and `n+1` would plug the lower `0`, and make a different number.\n\nIf there is a `0` in the very first bit, aka there is not an unbroken `1`, then a value of `-1` will have to be returned, as `n OR (n+1)` will always populate the `1`\'s column.\n\nTo calculate the position of the highest consecutive `1`, we can find the value of the lowest `0` and leftshift it by `1`. To find the value of the lowest `0`, we can `AND` the bitwise `NOT` of `n` with `n+1`. For the value of `v == 23` this would look like (`_` are for alignment padding):\n`23 ___ == 0b0000 0001 0111`\n`NOT 23 == 0b1111 1110 1000 == 23 ^ 0xFFF`\n`23 + 1 == 0b0000 0001 1000`\n`AND __ == 0b0000 0000 1000 == (23 ^ 0xFFF) & 23+1`\n`>> 1 _ == 0b0000 0000 0100 == ((23 ^ 0xFFF) & 23+1) >> 1`\n`v - n _== 0b0000 0001 0011 == 19`\n\nSubtracting this value from `v` gives us the minimum value of `n`.\n\n# Approach\nIterate through each element in the list. For each value:\n- Check if the there is a `1` in the `1`\'s column. If not, insert the value `-1` in the return array. As these are a list of primes, ignoring `2`, all primes will be odd, and therefor meet this condition. So this simply becomes a check to see if the value is equal to `2`.\n- Identify the value of the highest consecutive `1` using the above mentioned method of `(v ^ 0xFFF) &  v+1)`.\n- Subtract this value from the target prime and store it in the return array. \n\n# Complexity\n- Time complexity:\nSimple bitwise operations are performed on each element in the list once: $$O(n)$$\n\n- Space complexity:\nThe return array needs to be of the same size of the input array, as well as constant space for performing bitwise operations: $$O(n)$$\n\n# Code\n```python3 []\nclass Solution:\n    def minBitwiseArray(self, nums: List[int]) -> List[int]:\n        return [v - (((v^0xFFF) & v+1) >> 1)  if v != 2 else  -1  for v in nums ]\n```
['Bit Manipulation', 'Python3']