Practice Construct the Minimum Bitwise Array II
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
You are given an array nums consisting of n prime integers. You need to construct an array ans of length n, such that, for each index i, the bitwise OR of ans[i] and ans[i] + 1 is equal to nums[i], i.e. ans[i] OR (ans[i] + 1) == nums[i]. Additionally, you must minimize each value of ans[i] in the resulting array. If it is not possible to find such a value for ans[i] that satisfies the condition, then set ans[i] = -1.
Source: Construct the Minimum Bitwise Array II on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
nums = [2,3,5,7]
[-1,1,4,3]
# Example 2
nums = [11,13,31]
[9,12,15]
Constraints
Related LeetCode Problems
Practice more problems similar to Construct the Minimum Bitwise Array II.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.