1334. Maximum XOR of Two Numbers in Array (Trie)

MediumBit ManipulationXOR TrieBit ManipulationGreedy

Given an array of at least two non-negative integers, return the maximum value of nums[i] XOR nums[j] over all pairs of distinct positions.

Input: A JSON object {"nums": [<non-negative integers>]}.

Output: Return the maximum pairwise XOR.

Examples

Example 1
Input: {"nums":[3,10,5,25,2,8]}
Output: 28
Explanation: 5 XOR 25 = 28 is maximal.
Example 2
Input: {"nums":[0,0]}
Output: 0
Explanation: Both values are equal so the XOR is 0.

Constraints

Asked by

GoogleBloombergAmazonMicrosoftMeta
Solve this problem in the editor →