Data Structures & AlgorithmsModerateCodeforces Div 2 C · ICPC regional
Array [5, 2, 8, 1, 4, 6, 3]. How many index pairs i < j have a[i] AND a[j] = 0 (no common set bit)?
- A. 14
- B. 12
- C. 11
- D. 0
Correct answer: B. 12
Two numbers share no set bit exactly when their bitwise AND is zero. Checking all pairs is O(n^2), which is fine for this size; the pairs must be distinct positions, so a value does not pair with itself.
More Coding Interview Problems questions
- What is the minimum number of single-bit flips needed to change the 8-bit number 13 into the 8-bit number 22?
- Consider the eight primes 2, 3, 5, 7, 11, 13, 17, 19. How many subsets (including the empty subset, whose product is 1) have a product…
- How many 3-element subsets of {1, 2, 3, 4, 5, 6, 7, 8} have a sum divisible by 6?
- Half-open intervals [1,4), [2,6), [3,5), [5,8), [7,9), [8,10) are given. What is the largest number of them you can select so that no time…
- Meetings are closed-open intervals [1,3), [2,5), [4,6), [5,7), [6,9), [8,10) and one room can hold one meeting at a time. A meeting may…
- Sprinklers at positions p with radius r cover the closed interval [p - r, p + r] of a garden. The sprinklers are (1,2), (4,1), (7,3)…