Maximum Strong Pair XOR I - Problem
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:
|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: You can pick the same integer twice to form a pair.
Input & Output
Example 1 — Basic Case
$
Input:
nums = [1,2,3,5]
›
Output:
1
💡 Note:
Check all pairs: (1,1), (1,2), (2,2), (2,3), (3,3) are strong pairs. Among these, (2,3) gives maximum XOR: 2^3 = 1
Example 2 — Same Elements
$
Input:
nums = [5,6,25,30]
›
Output:
7
💡 Note:
Strong pairs: (5,5), (6,6), (5,6), (25,25), (30,30). Maximum XOR is from (5,6): 5^6 = 3. Wait, let me recalculate: (5,6) gives 5^6=3, but we also need to check other combinations
Example 3 — Single Element
$
Input:
nums = [10]
›
Output:
0
💡 Note:
Only one element, so only pair is (10,10). XOR of same numbers is 0: 10^10 = 0
Constraints
- 1 ≤ nums.length ≤ 50
- 1 ≤ nums[i] ≤ 100
Visualization
Tap to expand
Understanding the Visualization
1
Input Array
Given array with integers
2
Find Strong Pairs
Identify pairs where |x-y| ≤ min(x,y)
3
Calculate XOR
Find maximum XOR among valid pairs
Key Takeaway
🎯 Key Insight: Strong pairs have the constraint |x - y| ≤ min(x, y), which significantly limits the search space
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code