Data Structures & AlgorithmsHardICPC regional · GATE CS top band
Array A = [3, 31, 23, 2, 8, 19, 7] (all values below 32). What is the maximum of A[i] XOR A[j] over all index pairs with 0 ≤ i < j < 7?
- A. 54
- B. 31
- C. 28
- D. 1
Correct answer: B. 31
Inserting the values into a binary trie and choosing the opposite bit at each level finds the pair with XOR 31. Checking only neighbouring positions, or maximising the sum, gives other numbers.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- Distinct keys [5, 4, 7, 27, 25] are inserted, in the order given by the sequence [25, 5, 4, 27, 7], into an empty binary search tree. How…
- Consider the recursive function def f(n): if n < 2: return n; return f(n-1) + f(n-2). Evaluate f(7) and count every invocation of f…
- Consider the recursive function def f(n): if n < 2: return n; return f(n-1) + f(n-2). Evaluate f(10) and count every invocation of f…
- Array [25, 3, 24, 17, 29, 1] is turned into a min-heap in place with bottom-up heapify: for i from ⌊n/2⌋−1 down to 0, sift the element at…
- Array A = [8, 27, 25, 23, 28, 20, 13] (all values below 32). What is the maximum of A[i] XOR A[j] over all index pairs with 0 ≤ i < j < 7?
- Undirected weighted graph on vertices A, B, C, D, E; its edges, in this listed order, are: C–E (9), A–C (8), A–B (5), B–E (3), D–E (2)…