Data Structures & AlgorithmsHardCodeforces Div 2 C · ICPC regional

Array [1, 2, 4, 1, 3, 4]. How many contiguous subarrays have a bitwise OR of exactly 7?

  1. A. 13
  2. B. 10
  3. C. 11
  4. D. 3

Correct answer: C. 11

The OR of a subarray grows as the subarray extends, so for each start index the OR takes only a few distinct values. Counting subarrays whose element sum is 7 is a different condition.

More Coding Interview Problems questions

Exams that ask this topic