3314. Construct the Minimum Bitwise Array I Easy

@problem@discussion
#Array#Bit Manipulation



1/**
2 * [3314] Construct the Minimum Bitwise Array I
3 *
4 * You are given an array nums consisting of n <span data-keyword="prime-number">prime</span> integers.
5 * 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].
6 * Additionally, you must minimize each value of ans[i] in the resulting array.
7 * If it is not possible to find such a value for ans[i] that satisfies the condition, then set ans[i] = -1.
8 *  
9 * <strong class="example">Example 1:
10 * <div class="example-block">
11 * Input: <span class="example-io">nums = [2,3,5,7]</span>
12 * Output: <span class="example-io">[-1,1,4,3]</span>
13 * Explanation:
14 * 
15 * 	For i = 0, as there is no value for ans[0] that satisfies ans[0] OR (ans[0] + 1) = 2, so ans[0] = -1.
16 * 	For i = 1, the smallest ans[1] that satisfies ans[1] OR (ans[1] + 1) = 3 is 1, because 1 OR (1 + 1) = 3.
17 * 	For i = 2, the smallest ans[2] that satisfies ans[2] OR (ans[2] + 1) = 5 is 4, because 4 OR (4 + 1) = 5.
18 * 	For i = 3, the smallest ans[3] that satisfies ans[3] OR (ans[3] + 1) = 7 is 3, because 3 OR (3 + 1) = 7.
19 * </div>
20 * <strong class="example">Example 2:
21 * <div class="example-block">
22 * Input: <span class="example-io">nums = [11,13,31]</span>
23 * Output: <span class="example-io">[9,12,15]</span>
24 * Explanation:
25 * 
26 * 	For i = 0, the smallest ans[0] that satisfies ans[0] OR (ans[0] + 1) = 11 is 9, because 9 OR (9 + 1) = 11.
27 * 	For i = 1, the smallest ans[1] that satisfies ans[1] OR (ans[1] + 1) = 13 is 12, because 12 OR (12 + 1) = 13.
28 * 	For i = 2, the smallest ans[2] that satisfies ans[2] OR (ans[2] + 1) = 31 is 15, because 15 OR (15 + 1) = 31.
29 * </div>
30 *  
31 * Constraints:
32 * 
33 * 	1 <= nums.length <= 100
34 * 	2 <= nums[i] <= 1000
35 * 	nums[i] is a prime number.
36 * 
37 */
38pub struct Solution {}
39
40// problem: https://leetcode.com/problems/construct-the-minimum-bitwise-array-i/
41// discuss: https://leetcode.com/problems/construct-the-minimum-bitwise-array-i/discuss/?currentPage=1&orderBy=most_votes&query=
42
43// submission codes start here
44
45impl Solution {
46    pub fn min_bitwise_array(nums: Vec<i32>) -> Vec<i32> {
47        vec![]
48    }
49}
50
51// submission codes end
52
53#[cfg(test)]
54mod tests {
55    use super::*;
56
57    #[test]
58    fn test_3314() {
59    }
60}
61


Back
© 2025 bowen.ge All Rights Reserved.