Data Structures & AlgorithmsModerate

What is the sum, over all non-empty contiguous subarrays of 1 3 5, of the bitwise OR of each subarray?

  1. A. 30
  2. B. 26
  3. C. 24
  4. D. 12

Correct answer: B. 26

ORs: 1, 3, 5, 1|3 = 3, 3|5 = 7, 1|3|5 = 7, total 26. Adding the plain sums gives 30 because OR does not add overlapping bits, XOR gives 24, and AND gives 12.

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

Exams that ask this topic