Data Structures & AlgorithmsHardICPC regional · Codeforces Div2 B
Problem: The array [1, 2, 4, 8, 16, 32] stores powers of two. For how many pairs (i < j) is a[i] + a[j] a power of two?
- A. 1
- B. 0
- C. 2
- D. 3
Correct answer: B. 0
Two distinct powers of two set two different bits, so their sum has exactly two set bits and is never a power of two. The brute-force count is therefore zero.
More Coding Interview Problems questions
- Problem: A queue of 5 customers arrives with service times 4, 2, 6, 1, 3. A single server processes them in order (first come first…
- Problem: Starting with the list [3, 8, 2, 5], repeatedly take the last two elements, replace them by their difference (larger minus…
- Problem: How many 3-digit numbers (100–999) have digits that form a strictly increasing sequence when read left to right?
- Problem: In a list of the first 30 positive integers, how many numbers are multiples of 2 or 3 but not of 6?
- Problem: For the array [6, 1, 8, 3, 7], find the minimum number of adjacent swaps needed to sort it in increasing order (adjacent swaps…
- Problem: Starting at the number 2, repeatedly apply f(x) = x² + 1 modulo 11. What is the value after 5 applications?