Data Structures & AlgorithmsHard
How many contiguous subarrays of [5, 5, 3, 3, 6, 6, 6] have XOR equal to 0?
- A. 4
- B. 7
- C. 6
- D. 8
Correct answer: B. 7
Equal prefix XOR values bracket a zero-XOR subarray, so count pairs of equal prefix XORs including the initial 0. The claim that XOR-zero subarrays must have even length is false, and skipping the initial prefix also loses answers.
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
- How many index pairs i < j in [1, 5, 3, 3, 3, 7, 2, 4, 6] have DD[i] + DD[j] = 6? Equal values at different indices are different pairs.
- How many contiguous subarrays of [2, 1, 3, 1, 1, 2, 4, 1] have each element sum equal to its length (sum of (a[i] − 1) over the subarray…
- How many contiguous subarrays of [1, 2, 1, 2, 3, 3, 4] contain exactly 2 distinct values?
- In the array [2, 7, 3, 7, 1, 4], how many contiguous subarrays have their LEFT-most element equal to the maximum of the subarray (ties…
- How many contiguous subarrays of [1, 2, 1, 3, 2, 2, 1] have equal first and last elements and length at least 2?
- Counting subarrays whose sum is divisible by k with prefix remainders, which statement is TRUE?