Data Structures & AlgorithmsVery hard

How many contiguous subarrays of 1 2 4 3 5 2 have XOR equal to their SUM?

  1. A. 11
  2. B. 10
  3. C. 0
  4. D. 5

Correct answer: A. 11

XOR equals sum exactly when no two terms share a set bit, i.e. no carries occur, and the pairwise AND of terms is zero. Testing the inequalities or dropping singletons misreads this condition.

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

Exams that ask this topic