Maximum Strong Pair XOR I

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 that you can pick the same integer twice to form a pair.

Example 1
Inputnums = [1,2,3,4,5]
Output7
There are 11 strong pairs in nums, and the maximum XOR possible from these pairs is 3 XOR 4 = 7.
Example 2
Inputnums = [10,100]
Output0
Only (10, 10) and (100, 100) are strong pairs, and both have XOR value 0.

Constraints

  • 1 <= nums.length <= 50
  • 1 <= nums[i] <= 100

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate