Easy Bit Manipulation , not the best code. || PYTHON 3 ||
Intuition\nI noticed a pattern. Basically, the only even prime number is 2, and it doesn\'t have a number x such that x | x+1 = 2. Now for all the other prime n
# Intuition\nI noticed a pattern. Basically, the only even prime number is 2, and it doesn\'t have a number `x` such that `x | x+1 = 2`. Now for all the other prime numbers, we need to understand the pattern in the bit representation.\n\nTake \n`3`   => `11`  and the answer was `1` => `1`\n`5`   => `101` and the answer was `4` => `100`\n`11`  => `1011` and the answer was `9` => `1001`\n`13`  => `1101` and the answer was `12` => `1100`\n`31`  => `11111` and the answer was `15` => `1111`\n\nIf you notice, in all the cases, the answer is just differing from the number by just **1 BIT**.\n\nAnd that bit, is the `(rightmost index of 0)  + 1`.\nExample:  13 =>  `1101`   the rightmost index is at index 2, and the bit at index 3 is flipped, to get the answer!\n\n\nAnd in cases like `31` where there is no `0`, then the first bit is the bit that is flipped! \n\n\n\n\n# Approach\nSo the problem boils down to finding the index of the `rightmost 0` and flipping the bit next to it.\n\n# Complexity\n- Time complexity:\nO(N) for traversing through the list of `nums`\nO(log10 K) for traversing through the bits of each number in binary representation, where K is the maximum number in `nums`\n\n```\nO( N log10 K )\n```\n\n\n\n# Code\n```python3 []\nclass Solution:\n    def minBitwiseArray(self, nums: List[int]) -> List[int]:\n        s = []\n\n        for i in nums:\n            if (i == 2):   # because we know 2 doesn\'t have a solution\n                s.append(-1)\n\n            else:\n                b = str(bin(i))[2:]  # get the binary representation\n                try:\n                    indx = b.rindex("0") + 1\n                    if (b[indx] == "0"):\n                        d = "1"\n                    else:\n                        d = "0"\n\n                    c = eval("0b" + b[:indx] + d + b[indx + 1 :])  # construct the new integer\n              \n                except ValueError:  # incase 0 was not present in the binary representation\n                    c = eval("0b" + b[1:])\n                    \n            s.append(eval(c))\n\n\n        return s\n```
['Python3']