#2932
Easy Algorithms Maximum strong pair xor i
Array Hash Table Bit Manipulation Trie Sliding Window
75.9% acceptance
Feb 25, 2026
188
27
You are given a 0-indexed integer array nums. A pair of integers x and y is called a strong pair if:
|x - y| <= min(x, y)
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.
Return the maximum XOR value out of all possible strong pairs in the array nums.
Note that you can pick the same integer twice to form a pair.
Solution
Rust
Time O(n²)
Space O(1)
impl Solution {
pub fn maximum_strong_pair_xor(nums: Vec<i32>) -> i32 {
let mut ans = 0;
for &x in &nums {
for &y in &nums {
if (x - y).abs() <= x.min(y) {
ans = ans.max(x ^ y);
}
}
}
ans
}
}