Data Structures & AlgorithmsVery hardCodeforces Div2 D · TCS NQT

What is the length of the longest contiguous subarray of [4, 2, 2, 6, 4] whose bitwise XOR equals 6?

  1. A. 6
  2. B. 4
  3. C. 7
  4. D. 5

Correct answer: D. 5

Use prefix XORs: a subarray i..j has XOR K when P[j+1] XOR P[i] = K, so for each prefix find the earliest earlier prefix with the needed value. Searching only for XOR-zero subarrays answers a different question.

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

Exams that ask this topic