Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

How many ordered pairs (i, j) with i != j in [1, 3, 2, 6, 4] have a[i] AND a[j] = a[i], meaning the bits of a[i] are a subset of the bits of a[j]?

  1. A. 5
  2. B. 3
  3. C. 2
  4. D. 4

Correct answer: D. 4

The bitmask subset test is a AND b = a. Ordered pairs matter because subset-of is directional; the unordered variant (the last option) mis-counts.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic