Data Structures & AlgorithmsHardCodeforces Div2 C · TCS NQT

For the array [3, 5, 6, 1], compute the XOR of every non-empty contiguous subarray and add all these XOR values together. What is the total?

  1. A. 34
  2. B. 82
  3. C. 38
  4. D. 31

Correct answer: A. 34

Enumerate the start and extend the end while XOR-ing (O(n²)). Adding the subarray sums instead of their XORs is the common mix-up, and the two totals differ here.

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

Exams that ask this topic