Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
How many non-empty contiguous subarrays of [2, 4, 6, 1, 3, 1, 2, 4] have a bitwise XOR equal to 0?
- A. 5
- B. 3
- C. 2
- D. 36
Correct answer: B. 3
Prefix XORs: a subarray has XOR 0 exactly when two prefix XOR values are equal, so count equal pairs of prefixes with a hash map. Forgetting that the prefix of length 0 has XOR 0 loses some subarrays.
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
- What is the length of the shortest contiguous substring of "xaybzcabbc" that contains "abc" as a SUBSEQUENCE (the letters appear in order…
- How many index triples i < j < k in "abacbab" spell a palindrome of length 3, meaning s[i] = s[k]? (The middle letter is unrestricted.)
- What is the smallest integer x ≥ 100 whose binary representation contains exactly 4 ones?
- Items of sizes [4, 8, 1, 4, 2, 1] must be packed into bins of capacity 10 with no bin over capacity. What is the minimum number of bins…
- How many binary strings of length 8 contain no two adjacent 1s and an EVEN number of 0s?
- The string "abaccbbca" is split into contiguous palindromic pieces. A piece of length L costs L². What is the minimum total cost?