Data Structures & AlgorithmsHard

Why is a sum of XORs over subarrays NOT equal to the sum of the subarray sums?

  1. A. XOR of a subarray is always zero.
  2. B. XOR does not distribute over addition: carries in addition have no counterpart in XOR, so the two totals differ.
  3. C. Subarray sums are always smaller than their XORs.
  4. D. Both operations are identical on non-negative integers.

Correct answer: B. XOR does not distribute over addition: carries in addition have no counterpart in XOR, so the two totals differ.

The XOR of a block drops the carries that addition would propagate, so the two quantities are different functions of the block. A direct computation of each subarray's XOR is needed.

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

Exams that ask this topic