Data Structures & AlgorithmsModerate

How many DISTINCT values arise as the bitwise OR of a non-empty contiguous subarray of 1 2 4 2?

  1. A. 10
  2. B. 3
  3. C. 6
  4. D. 7

Correct answer: C. 6

OR values stay within a small set because each new element can only add bits; collect the set of OR values over all blocks. Counting blocks, counting blocks of length at least 2, or counting distinct inputs measures other things.

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

Exams that ask this topic