💡 [EASY] INTUITION & EXPLANATION
\n\n# \uD83D\uDC93**_PLEASE CONSIDER UPVOTING_**\uD83D\uDC93\n\n \n\n\n# \u2B50 Problem Overview\nIn this problem, you are tasked with constructing an array ans
<div align="center">\n\n# \uD83D\uDC93**_PLEASE CONSIDER UPVOTING_**\uD83D\uDC93\n\n</div>\n\n***\n# \u2B50 Problem Overview\nIn this problem, you are tasked with constructing an array `ans` from an array `nums` of prime integers. For each index `i`, the relationship that must hold is `ans[i] | (ans[i] + 1) = nums[i]`. The challenge is to minimize each value of `ans[i]` while ensuring the condition is satisfied.\n\n# \u2B50 Differences from the First Part of the Question\nThe first part of the question allows for a more straightforward search for `ans[i]`, since there are fewer constraints on the values in `nums`. However, in this second part:\n\n- **Tight Constraints**: \n  - The constraints are stricter, with `nums[i]` being guaranteed as a prime number. Prime numbers have specific properties in terms of their binary representation, which restricts the possible values for `ans[i]`.\n  - Additionally, each number in `nums` can be as large as 10^9, meaning that naive brute-force searching would be inefficient.\n\n# \u2B50 Intuition\nGiven the properties of prime numbers, any prime number `p` can be expressed in binary, and the task requires finding an `ans[i]` such that the bitwise OR operation with its successor produces the prime number itself. This requires a careful examination of each bit in the prime.\n\n# \u2B50 Approach\n1. **Initialization**: \n   - We start by creating an output array `ans`, where we will store our results.\n\n2. **Iterate Through Each Prime Number**: \n   - For each number in `nums`, we initialize `minimalValue` to a very large number (Integer.MAX_VALUE) to ensure that any valid candidate found will be smaller.\n\n3. **Bit Position Examination**: \n   - Unlike the first part of the problem, which could iterate through all possible values below the prime, we focus specifically on the bit positions of the current prime number. \n   - We only check for bits that are set in `num`, because unsetting a bit in a prime should ideally lead us to the next smaller candidate that still satisfies the condition.\n\n4. **Finding Candidates**: \n   - When we unset a bit in `num`, we form a candidate. The candidate must be checked to see if it meets the requirement: `(candidate | (candidate + 1)) == num`.\n   - The search for candidates is limited to 30 iterations because we are working within the constraint of 10^9, which fits within 30 bits.\n\n5. **Store Valid Results**: \n   - If a valid candidate is found for a particular `num`, we update `minimalValue`. If no valid candidate is found after checking all relevant bit positions, we set `ans[i]` to -1.\n   \n6. **Return the Result**: \n   - Finally, we return the constructed `ans` array containing the minimal values or -1 where appropriate.\n\n# \u2B50 Code\n```java []\nclass Solution { \n    public int[] minBitwiseArray(List<Integer> arr) {\n        int[] ans = new int[arr.size()];\n        int index = 0;\n\n        for (int num : arr) {\n            int minimalValue = Integer.MAX_VALUE;\n            boolean isValid = false;\n\n            for (int bitPosition = 0; bitPosition <= 30; bitPosition++) {\n                if ((num & (1 << bitPosition)) != 0) {\n                    int candidate = num & ~(1 << bitPosition);\n                    if (candidate >= 0 && (candidate | (candidate + 1)) == num) {\n                        if (candidate < minimalValue) {\n                            minimalValue = candidate;\n                            isValid = true;\n                        }\n                    }\n                }\n            }\n            ans[index++] = isValid ? minimalValue : -1;\n        }\n        \n        return ans;\n    }\n}\n```
['Bit Manipulation', 'Bitmask', 'Java']