Data Structures & AlgorithmsModerate

What is the sum, over all non-empty contiguous subarrays of 5 3 6 1 4, of their XOR values, taken modulo 1000?

  1. A. 131
  2. B. 555
  3. C. 55
  4. D. 56

Correct answer: C. 55

Compute each subarray's XOR directly (XOR is not additive, so the sum of subarray sums is not the answer), add the values, and reduce modulo 1000 last. Summing the ordinary sums or skipping the modulus gives other totals.

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

Exams that ask this topic