2935. Maximum Strong Pair XOR II Hard
1/**
2 * [2935] Maximum Strong Pair XOR II
3 *
4 * You are given a 0-indexed integer array nums. A pair of integers x and y is called a strong pair if it satisfies the condition:
5 *
6 * |x - y| <= min(x, y)
7 *
8 * You need to select two integers from nums such that they form a strong pair and their bitwise XOR is the maximum among all strong pairs in the array.
9 * Return the maximum XOR value out of all possible strong pairs in the array nums.
10 * Note that you can pick the same integer twice to form a pair.
11 *
12 * <strong class="example">Example 1:
13 *
14 * Input: nums = [1,2,3,4,5]
15 * Output: 7
16 * Explanation: There are 11 strong pairs in the array nums: (1, 1), (1, 2), (2, 2), (2, 3), (2, 4), (3, 3), (3, 4), (3, 5), (4, 4), (4, 5) and (5, 5).
17 * The maximum XOR possible from these pairs is 3 XOR 4 = 7.
18 *
19 * <strong class="example">Example 2:
20 *
21 * Input: nums = [10,100]
22 * Output: 0
23 * Explanation: There are 2 strong pairs in the array nums: (10, 10) and (100, 100).
24 * The maximum XOR possible from these pairs is 10 XOR 10 = 0 since the pair (100, 100) also gives 100 XOR 100 = 0.
25 *
26 * <strong class="example">Example 3:
27 *
28 * Input: nums = [500,520,2500,3000]
29 * Output: 1020
30 * Explanation: There are 6 strong pairs in the array nums: (500, 500), (500, 520), (520, 520), (2500, 2500), (2500, 3000) and (3000, 3000).
31 * The maximum XOR possible from these pairs is 500 XOR 520 = 1020 since the only other non-zero XOR value is 2500 XOR 3000 = 636.
32 *
33 *
34 * Constraints:
35 *
36 * 1 <= nums.length <= 5 * 10^4
37 * 1 <= nums[i] <= 2^20 - 1
38 *
39 */
40pub struct Solution {}
41
42// problem: https://leetcode.com/problems/maximum-strong-pair-xor-ii/
43// discuss: https://leetcode.com/problems/maximum-strong-pair-xor-ii/discuss/?currentPage=1&orderBy=most_votes&query=
44
45// submission codes start here
46
47impl Solution {
48 pub fn maximum_strong_pair_xor(nums: Vec<i32>) -> i32 {
49 0
50 }
51}
52
53// submission codes end
54
55#[cfg(test)]
56mod tests {
57 use super::*;
58
59 #[test]
60 fn test_2935() {
61 }
62}
63
Back
© 2025 bowen.ge All Rights Reserved.