Data Structures & AlgorithmsHardICPC regional · GATE CS top band
Array A = [30, 14, 22, 26, 8, 7] (all values below 32). What is the maximum of A[i] XOR A[j] over all index pairs with 0 ≤ i < j < 6?
- A. 30
- B. 24
- C. 4
- D. 56
Correct answer: A. 30
Inserting the values into a binary trie and choosing the opposite bit at each level finds the pair with XOR 30. 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
- Words ['abd', 'bd', 'dac', 'cac', 'dcb', 'dab', 'dcc'] (each may be used at most once). A chain is a sequence of these words in which the…
- Connected undirected weighted graph on vertices A, B, C, D, E, F with edges A–B (14), A–C (14), A–D (6), A–E (3), B–C (16), B–D (20), B–E…
- Undirected weighted graph on vertices A, B, C, D, E, F with edges A–C (6), A–D (9), A–E (3), A–F (6), B–C (7), B–E (3), B–F (3), D–F (3)…
- Directed acyclic graph on vertices A, B, C, D, E with edges A→C, A→E, E→B. Among all topological orderings (every edge goes from earlier…
- Distinct keys [6, 20, 4, 25, 16] are inserted, in the order given by the sequence [16, 25, 20, 6, 4], into an empty binary search tree…
- Undirected simple graph on vertices A, B, C, D, E, F, G with edges A–D (1), A–F (1), A–G (1), B–C (1), B–G (1), C–D (1), C–G (1), E–G (1)…