Data Structures & AlgorithmsHardProduct Company SDE · ICPC regional
Problem: What is the maximum value of a XOR b over all pairs (a, b) taken from the array [3, 10, 5, 25, 2, 8] (a and b may be equal)?
- A. 29
- B. 35
- C. 28
- D. 31
Correct answer: C. 28
A bitwise trie (or checking all pairs) finds 5 XOR 25 = 00101 XOR 11001 = 11100 = 28. Using OR instead gives 25 | 5 = 29, maximising the sum gives 35, and XOR-ing the whole array gives 31.
More Coding Interview Problems questions
- Problem: The minimum number of characters to delete from "(()))(" to make the parentheses balanced (every ( has a matching ) after it) is…
- Problem: Selection sort is applied to [4, 3, 2, 1] and the number of element moves (assignments into the array) is counted as one per…
- Problem: In a 3-row Pascal-like grid, a cell holds the number of ways to reach it moving only right or down from (0,0), with a blocked…
- Problem: Using Dijkstra from node 0 on the undirected graph with edges (0,1,2), (1,2,2), (0,2,5), (2,3,1), how many nodes have shortest…
- Problem: How many simple paths go from 0 to 3 in the undirected graph with edges 0-1, 1-2, 2-3, 3-0 and the chord 0-2? Run the DFS code…
- Problem: How many ordered pairs (a, b) with 1 <= a <= b <= 20 have gcd(a, b) = 1? Run the code. python from math import gcd print(sum(1…