Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2
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?
- A. 31
- B. 55
- C. 2
- D. 25
Correct answer: A. 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 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)…
- Union–find on elements 0 to 7, all starting as singletons, with no path compression. union(x, y): let rx, ry be the roots of x and y; if…
- 2 × 3 sliding puzzle with tiles 1 to 5 and one blank (shown as ). Current board: 4 1 3 / 2 5 . Goal board: 1 2 3 / 4 5 . A move slides a…
- Directed graph on vertices A, B, C, D, E, F with edges D→E, A→B, C→D, F→E, F→C, E→D, A→D, C→A. How many strongly connected components does…
- Undirected simple graph on vertices A, B, C, D, E, F with edges A–C (1), B–D (1), B–E (1), B–F (1), C–D (1), C–E (1), C–F (1), D–E (1)…
- Directed acyclic graph on vertices A, B, C, D, E, F, G (edges go from earlier to later letters) with weights A→B (3), A→D (4), A→E (4)…