[Java/Python 3] Bit Manipulation w/ brief explanation and analysis.
Intuition:\n1. ans[i] | (ans[i] + 1) must be odd, therefore there is no way to find an ans[i] such that ans[i] | (ans[i] + 1) = 2; Hence, return -1 for 2;\n2. B
**Intuition:**\n1. `ans[i] | (ans[i] + 1)` must be odd, therefore there is no way to find an `ans[i]` such that `ans[i] | (ans[i] + 1) = 2`; Hence, return `-1` for `2`;\n2. By observation, for any given binary number `0...1...0...11...1`, only the ending `11....1` part can be minimized to `01...1` such that `01...1 + 1 = 10...0`, hence `01...1 | 10...0 = 11...1`. That is, **remove the one bit just right of right-most zero bit**:\n\n`01...1`\n`10...0`\n\n--\n`11...1`\n\nTherefore, we can isolate this kind of ending to minimize the result.\n\n```java\n    public int[] minBitwiseArray(List<Integer> nums) {\n        int[] ans = new int[nums.size()];\n        for (int i = 0; i < nums.size(); ++i) {\n            ans[i] = getVal(nums.get(i));\n        }\n        return ans;\n    }\n    private int getVal(int x) {\n        if (x == 2) {\n            return -1;\n        } \n        int lowestOneBit = Integer.lowestOneBit(x + 1);\n        x -= lowestOneBit >> 1;\n        return x;\n    }\n```\n\n```python\n    def minBitwiseArray(self, nums: List[int]) -> List[int]:\n        ans = []\n        for x in nums:\n            if x == 2:\n                ans.append(-1)\n            else:\n                lowest_one_bit = (x + 1) & -(x + 1)\n                x -= lowest_one_bit >> 1\n                ans.append(x)    \n        return ans\n```\n\nor\n\n```python\n    def minBitwiseArray(self, nums: List[int]) -> List[int]:\n        ans = []\n        for x in nums:\n            if x == 2:\n                ans.append(-1)\n            else:\n                y = 0\n                for i in range(x.bit_length() - 1, -1, -1):\n                    if (x + 1).bit_count() == 1:\n                        y += x // 2\n                        break\n                    if (x & (1 << i)) > 0:\n                        y += 1 << i\n                        x -= 1 << i\n                ans.append(y)    \n        return ans\n```\n\nMake the above codes shorter:\n```java\n    public int[] minBitwiseArray(List<Integer> nums) {\n        return nums.stream().mapToInt(this::getVal).toArray();\n    }\n    private int getVal(int x) {\n        return x == 2 ? -1 : x - (Integer.lowestOneBit(x + 1) >> 1);\n    }\n```\n\n```python\n    def minBitwiseArray(self, nums: List[int]) -> List[int]:\n        return [-1 if x == 2 else x - (((y := x + 1) & -y) >> 1) for x in nums]\n```\n\n**Analysis:**\n\nTime: `O(nlog(max))`, space: `O(1)`- excluding output space, where `n = nums.length, max = max(nums)`.\n
['Bit Manipulation', 'Java', 'Python3']