dsa1 min read
Maximum XOR of Two Numbers — Binary Trie
Find maximum XOR of any two numbers in array. Binary trie (bit by bit from MSB): for each number greedily choose opposite bit to maximize XOR.
Read →
1575 articles
Find maximum XOR of any two numbers in array. Binary trie (bit by bit from MSB): for each number greedily choose opposite bit to maximize XOR.
After each character typed, return up to 3 lexicographically smallest matching products. Sort products, insert into trie, store sorted lists at each node.
Find longest word where all prefixes exist in dictionary. Trie: only follow nodes where is_end=True, track max depth.
Find pairs (i,j) where words[i]+words[j] is a palindrome. Insert reversed words into trie, for each word check palindromic suffix/prefix conditions.
Query if any word ends at the current stream position. Insert reversed words into trie; maintain suffix deque to match from current position backwards.