Data Structures & AlgorithmsModerateCodeforces Div 2 C · ICPC regional

Array [1, 2, 3, 4, 5, 6, 7, 0]. How many index pairs i < j satisfy (a[i] OR a[j]) = 7?

  1. A. 15
  2. B. 12
  3. C. 13
  4. D. 0

Correct answer: C. 13

OR equals 7 when the two values together cover all three bits. Enumerate pairs and test the OR directly; the AND condition is a different relation, which is the common confusion.

More Coding Interview Problems questions

Exams that ask this topic