Data Structures & AlgorithmsHard

For the array 1 2 3 4, how many DISTINCT values appear as the XOR of a non-empty contiguous subarray?

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

Correct answer: C. 7

Enumerate the XOR of every non-empty block and count distinct results; many blocks share a value here. Counting blocks gives the subarray total, and the prefix XORs (including 0) are a different set.

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

Exams that ask this topic