Maximum XOR

hard

Find maximum XOR of any two numbers in array

Maximum XOR

Key Insight

XOR is maximized when bits differ most. Compare all pairs (optimal: Trie).

Step 1Problem
No binary data

Find max XOR of any two numbers in [3, 10, 5, 25, 2, 8].

1 / 5

Learn the Pattern

Practice the Code

Step-by-Step Walkthrough: Maximum XOR

XOR is maximized when bits differ most. Compare all pairs (optimal: Trie).

  1. Problem

    Find max XOR of any two numbers in [3, 10, 5, 25, 2, 8].

  2. Key Insight

    XOR is max when MSBs differ. 25 starts with 1 at bit 4.

  3. Try Pairs

    25 ^ 5 = 28. High XOR because MSBs differ.

  4. Compare More

    25 ^ 2 = 27. Not quite as high.

  5. Result

    Maximum XOR = 28 (from 25 ^ 5)