3670. Maximum Product of Two Integers With No Common Bits Medium
1/**
2 * [3670] Maximum Product of Two Integers With No Common Bits
3 *
4 * You are given an integer array nums.
5 * Your task is to find two distinct indices i and j such that the product nums[i] * nums[j] is maximized, and the binary representations of nums[i] and nums[j] do not share any common set bits.
6 * Return the maximum possible product of such a pair. If no such pair exists, return 0.
7 *
8 * <strong class="example">Example 1:
9 * <div class="example-block">
10 * Input: <span class="example-io">nums = [1,2,3,4,5,6,7]</span>
11 * Output: <span class="example-io">12</span>
12 * Explanation:
13 * The best pair is 3 (011) and 4 (100). They share no set bits and 3 * 4 = 12.
14 * </div>
15 * <strong class="example">Example 2:
16 * <div class="example-block">
17 * Input: <span class="example-io">nums = [5,6,4]</span>
18 * Output: <span class="example-io">0</span>
19 * Explanation:
20 * Every pair of numbers has at least one common set bit. Hence, the answer is 0.
21 * </div>
22 * <strong class="example">Example 3:
23 * <div class="example-block">
24 * Input: <span class="example-io">nums = [64,8,32]</span>
25 * Output: <span class="example-io">2048</span>
26 * Explanation:
27 * No pair of numbers share a common bit, so the answer is the product of the two maximum elements, 64 and 32 (64 * 32 = 2048).
28 * </div>
29 *
30 * Constraints:
31 *
32 * 2 <= nums.length <= 10^5
33 * 1 <= nums[i] <= 10^6
34 *
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/maximum-product-of-two-integers-with-no-common-bits/
39// discuss: https://leetcode.com/problems/maximum-product-of-two-integers-with-no-common-bits/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44 pub fn max_product(nums: Vec<i32>) -> i64 {
45
46 }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_3670() {
57 }
58}
59Back
© 2026 bowen.ge All Rights Reserved.