Data Structures & AlgorithmsHardCodeforces Div 2 · ICPC regional
Array A = [25, 23, 7, 3, 1] (all values below 32). What is the maximum of A[i] XOR A[j] over all index pairs with 0 ≤ i < j < 5?
- A. 16
- B. 2
- C. 48
- D. 30
Correct answer: D. 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
- Keys are inserted in the order 51 18 15 34 11 into an empty binary search tree. Then the key 18 (which has two children) is deleted by…
- Connected undirected graph on vertices A, B, C, D, E, F, G, H with edges A–C (1), B–D (1), B–E (1), B–G (1), C–D (1), D–F (1), D–G (1)…
- Undirected weighted graph on vertices A, B, C, D, E, F; its edges, in this listed order, are: A–C (7), B–D (9), A–D (6), A–E (5), B–F (6)…
- Points A(5,6), B(6,6), C(4,5), D(7,8), E(7,6) in the plane. The cost of joining two points is the Manhattan distance |x1−x2| + |y1−y2|…
- Dictionary D = {bdc, bds, cat, gce, lpb, nig, pgm, rmm, seg, tgm, tgs, tms} (all words have 3 letters). Starting from the word 'pmm', a…
- Undirected graph on vertices A, B, C, D, E, F with edges, in this exact order: C–D (1), B–C (1), C–E (1), C–F (1), A–D (1), A–C (1)…