Data Structures & AlgorithmsHardICPC regional · GATE CS top band
Array A = [29, 1, 24, 26, 13, 6, 8] (all values below 32). What is the maximum of A[i] XOR A[j] over all index pairs with 0 ≤ i < j < 7?
- A. 2
- B. 55
- C. 30
- D. 28
Correct answer: C. 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
- Directed weighted graph on vertices A, B, C, D, E, F with edges listed in this exact order: A→D (7); C→E (0); D→B (2); F→A (2); C→D (5)…
- Keys are inserted in the order 56 88 11 17 79 25 68 into an empty binary search tree. Then the key 56 (which has two children) is deleted…
- Array A = [3, 1, 2, 3, 4, 1, 4, 1, 4]. An increasing subsequence is chosen by INDEX positions i1 < i2 < … with A[i1] < A[i2] < … (strictly…
- Connected undirected graph on vertices A, B, C, D, E, F, G, H with edges A–D (1), B–F (1), B–H (1), C–D (1), D–E (1), D–H (1), E–G (1)…
- Weighted tree on vertices 0 to 6 with edges 0–1 (7), 1–2 (8), 0–3 (7), 0–4 (2), 0–5 (1), 1–6 (8). What is the largest possible sum of edge…
- Directed graph on vertices 0 to 4 with weighted edges (u→v (w)); some weights are negative: 0→4 (8), 1→4 (-1), 0→1 (6), 3→1 (-2), 0→3 (7)…