Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2
Array A = [11, 19, 21, 15, 20] (all values below 32). What is the maximum of A[i] XOR A[j] over all index pairs with 0 ≤ i < j < 5?
- A. 1
- B. 27
- C. 41
- D. 31
Correct answer: D. 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
- Undirected simple graph on vertices A, B, C, D, E, F, G with edges A–B (1), A–C (1), A–D (1), A–E (1), C–E (1), C–F (1), C–G (1), D–F (1)…
- A chain of 5 matrices M1 to M5 has dimensions given by the sequence p = [11, 8, 3, 12, 16, 9], where Mi has size p[i−1] × p[i]…
- Undirected graph on vertices A, B, C, D, E, F with weighted edges A–B (4), A–C (7), A–E (3), B–C (6), B–E (4), B–F (2), C–D (7), C–F (2)…
- Undirected weighted graph on vertices A, B, C, D, E with edges A–D (1), B–D (2), B–E (1), C–D (1), C–E (2), D–E (3). An edge is CRITICAL…
- Strings a = "accabb" and b = "aaab". The edit distance allows insert, delete and substitute, each costing 1 (the standard Levenshtein…
- Undirected graph on vertices A, B, C, D, E, F with edges A–B (1), A–E (1), B–C (1), B–D (1), B–E (1), B–F (1), C–D (1), D–E (1) (weights…