Data Structures & AlgorithmsHardCodeforces Div2 C · TCS NQT
For the array [3, 5, 6, 1], compute the XOR of every non-empty contiguous subarray and add all these XOR values together. What is the total?
- A. 34
- B. 82
- C. 38
- D. 31
Correct answer: A. 34
Enumerate the start and extend the end while XOR-ing (O(n²)). Adding the subarray sums instead of their XORs is the common mix-up, and the two totals differ here.
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 non-empty contiguous subarrays of [2, 4, 6, 1, 3, 1, 2, 4] have a bitwise XOR equal to 0?
- 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?