Skip to content
BytePatterns

Maximum XOR Pair

HardTries#bit-trie#greedy~40m

Problem

Given a list of non-negative integers, return the largest value obtainable by taking the bitwise XOR of two of them. The two may be the same element only if that element appears twice.

Examples

Input:  nums = [3, 10, 5, 25, 2, 8]
Output: 28
Why:    5 XOR 25 is 28, and no other pair beats it
Input:  nums = [8, 10, 2]
Output: 10
Why:    8 XOR 2 is 10, which beats 8 XOR 10 and 10 XOR 2
Input:  nums = [1, 1]
Output: 0
Why:    edge case, identical values cancel to zero

Hints

0 / 3

Stuck on the idea rather than the code? Trie vs Hash Set covers it.