Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

How many contiguous subarrays of [1, 2, 3, 4, 5] have a bitwise XOR less than 4?

  1. A. 12
  2. B. 8
  3. C. 10
  4. D. 14

Correct answer: C. 10

XOR is not monotone in the subarray length, so no sliding window works directly. Prefix XOR with a bit-trie or direct enumeration on this small array is the reliable route.

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

Exams that ask this topic