Data Structures & AlgorithmsModerate

How many contiguous subarrays of length exactly 3 in 1 2 3 4 4 1 5 7 have bitwise XOR equal to 0?

  1. A. 4
  2. B. 2
  3. C. 0
  4. D. 1

Correct answer: B. 2

XOR of three values is zero exactly when the third equals the XOR of the first two, which is a direct test per window. Counting the complement, testing the sum, or checking pairs answers different questions.

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

Exams that ask this topic