Data Structures & AlgorithmsVery hardCodeforces Div 2 C · ICPC regional
How many pairs of integers (x, y) with 1 <= x < y <= 12 satisfy x XOR y = x + y?
- A. 25
- B. 23
- C. 22
- D. 43
Correct answer: B. 23
x + y = (x XOR y) + 2(x AND y), so equality holds exactly when x AND y = 0, meaning no shared set bits. Checking the pairs directly confirms the count.
More Coding Interview Problems questions
- Sorted side lengths [3, 5, 7, 9, 11, 13]. How many triples of distinct sides form a non-degenerate triangle with perimeter at most 20?
- Problem: A 3×4 grid holds entry costs (row by row): [[1, 3, 1, 2], [1, 5, 1, 9], [4, 2, 1, 1]]. Starting at the top-left cell, you may…
- Problem: A directed graph on vertices 0–7 has arcs 0→1, 0→2, 1→3, 2→3, 3→4, 4→5, 2→6, 6→7. How many vertices are reachable from vertex 0…
- Problem: A 4×4 grid has obstacles at (1,1), (1,2), (2,1) (row, column, 0-indexed). Movement is up, down, left or right. How many distinct…
- Problem: An undirected graph on 9 vertices (0–8) has edges 0-1, 1-2, 3-4, 4-5, 5-3, 6-7. Vertex 8 is isolated. Count the unordered pairs…
- Problem: A rooted tree (root 1) has children lists: 1: [2, 3, 4], 2: [5, 6], 3: [], 4: [7], 5: [], 6: [8, 9], 7: [], 8: [], 9: []. How…