Data Structures & AlgorithmsVery hard
Which statement about subarrays with XOR equal to 0 is CORRECT?
- A. Such a subarray must have even length.
- B. The prefix XOR array must be strictly increasing for the count to be valid.
- C. Two prefix-XOR values are equal exactly when the subarray between them has XOR 0.
- D. Subarray XOR cannot be derived from prefix XOR values.
Correct answer: C. Two prefix-XOR values are equal exactly when the subarray between them has XOR 0.
If p[i] = p[j] then the XOR of elements i..j−1 cancels to 0, and the converse holds too. Length 3 subarrays such as [1, 2, 3] can have XOR 0, so the even-length claim is false.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- A zero-sum subarray counter keeps a map of prefix sums. At each index the current prefix is inserted into the map BEFORE the lookup. What…
- For pairs i < j with (ai + aj) divisible by an EVEN number m, with remainder counts cr, which formula is correct?
- Which statement about counting subarrays with EXACTLY k distinct values is correct?
- Positive integers, two pointers count subarrays with product less than K. Why is right − left + 1 added for each right end?
- Which statement about inversion counting with repeated values is correct?
- Houses stand in a circle with values [5, 1, 9, 8, 4, 6, 2, 7]. Adjacent houses cannot both be robbed, and the first and last houses are…