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)?

  1. A. 14
  2. B. 12
  3. C. 11
  4. 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

Exams that ask this topic