XOR Problems (Trie)
Learn XOR Problems (Trie) (Trie, Advanced DSA) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
Maximum XOR of Two Numbers in an Array Naive approach checks every pair - O(n²). Insert every number into a Binary Trie, then for EACH number, greedily walk the Trie preferring the OPPOSITE bit at every level (maximizing XOR contribution) - O(n × BITS), dramatically faster.