Data Structures & AlgorithmsHardCodeforces Div2 D · bitwise tries
Problem: What is the maximum XOR of any two different elements of the array [3, 10, 5, 25, 2, 8]?
Problem: What is the maximum XOR of any two different elements of the array [3, 10, 5, 25, 2, 8]?
a = [3, 10, 5, 25, 2, 8] print(max(x ^ y for i, x in enumerate(a) for y in a[i + 1:]))What is printed?
- A. 27
- B. 28
- C. 25
- D. 31
Correct answer: B. 28
The maximum comes from 5 XOR 25 = 28. A binary trie solves the same question in O(n * 31) time, which is the intended approach for large n.
More Coding Interview Problems questions
- Problem: What is the length of the longest contiguous subarray containing at most two distinct values? python from collections import…
- Problem: Remove exactly 3 digits from the number '1432219' to make the smallest possible number, keeping the remaining digits in order…
- Problem: What is the length of the longest palindromic subsequence of 'bbbab'? python def lps(s): n = len(s) dp = [[0] n for in range(n)]…
- Problem: Multiply a chain of matrices with dimensions p = [10, 30, 5, 60] (matrix i is p[i] by p[i+1]). Find the minimum number of scalar…
- Problem: How many ways can 10 be formed as an ordered-free sum of coins 1, 2 and 5 (each coin may be used any number of times, and order…
- Problem: What is the diameter (in edges) of the tree with edges 1-2, 2-3, 2-4, 4-5, 5-6? Use the double BFS code. python from collections…