950. Maximum XOR of Two Numbers (Trie Bitwise)

HardTreesTrieBit Manipulation

Given an array of non-negative integers, return the maximum value of nums[i] XOR nums[j] over all pairs i, j. If the array has fewer than two elements, return 0. The input is a JSON array.

Input: A JSON array of non-negative integers.

Output: Integer — the maximum pairwise XOR.

Examples

Example 1
Input: [3,10,5,25,2,8]
Output: 28
Explanation: 5 XOR 25 = 28.
Example 2
Input: [0]
Output: 0
Explanation: Fewer than two elements.
Example 3
Input: [8,10,2]
Output: 10
Explanation: 8 XOR 2 = 10.

Constraints

Asked by

AmazonGoogleMicrosoftMetaAdobe
Solve this problem in the editor →