1969. Minimum Non-Zero Product of the Array Elements Medium
1/**
2 * [1969] Minimum Non-Zero Product of the Array Elements
3 *
4 * You are given a positive integer p. Consider an array nums (1-indexed) that consists of the integers in the inclusive range [1, 2^p - 1] in their binary representations. You are allowed to do the following operation any number of times:
5 *
6 * Choose two elements x and y from nums.
7 * Choose a bit in x and swap it with its corresponding bit in y. Corresponding bit refers to the bit that is in the same position in the other integer.
8 *
9 * For example, if x = 11<u>0</u>1 and y = 00<u>1</u>1, after swapping the 2^nd bit from the right, we have x = 11<u>1</u>1 and y = 00<u>0</u>1.
10 * Find the minimum non-zero product of nums after performing the above operation any number of times. Return this product modulo 10^9 + 7.
11 * Note: The answer should be the minimum product before the modulo operation is done.
12 *
13 * Example 1:
14 *
15 * Input: p = 1
16 * Output: 1
17 * Explanation: nums = [1].
18 * There is only one element, so the product equals that element.
19 *
20 * Example 2:
21 *
22 * Input: p = 2
23 * Output: 6
24 * Explanation: nums = [01, 10, 11].
25 * Any swap would either make the product 0 or stay the same.
26 * Thus, the array product of 1 * 2 * 3 = 6 is already minimized.
27 *
28 * Example 3:
29 *
30 * Input: p = 3
31 * Output: 1512
32 * Explanation: nums = [001, 010, 011, 100, 101, 110, 111]
33 * - In the first operation we can swap the leftmost bit of the second and fifth elements.
34 * - The resulting array is [001, <u>1</u>10, 011, 100, <u>0</u>01, 110, 111].
35 * - In the second operation we can swap the middle bit of the third and fourth elements.
36 * - The resulting array is [001, 110, 0<u>0</u>1, 1<u>1</u>0, 001, 110, 111].
37 * The array product is 1 * 6 * 1 * 6 * 1 * 6 * 7 = 1512, which is the minimum possible product.
38 *
39 *
40 * Constraints:
41 *
42 * 1 <= p <= 60
43 *
44 */
45pub struct Solution {}
46
47// problem: https://leetcode.com/problems/minimum-non-zero-product-of-the-array-elements/
48// discuss: https://leetcode.com/problems/minimum-non-zero-product-of-the-array-elements/discuss/?currentPage=1&orderBy=most_votes&query=
49
50// submission codes start here
51
52impl Solution {
53 pub fn min_non_zero_product(p: i32) -> i32 {
54 0
55 }
56}
57
58// submission codes end
59
60#[cfg(test)]
61mod tests {
62 use super::*;
63
64 #[test]
65 fn test_1969() {
66 }
67}
68
Back
© 2025 bowen.ge All Rights Reserved.