Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div2 B
What is the sum of the XOR of every non-empty contiguous subarray of [1, 2, 3]?
- A. 10
- B. 12
- C. 7
- D. 14
Correct answer: A. 10
Single elements give 1, 2, 3. The pairs give 3 and 1, and the whole array gives 0. Each subarray is counted once, not once per prefix.
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 contiguous subarrays of [2, 4, 8, 3, 6] have an LCM equal to their maximum element?
- How many ordered triples (i, j, k) of distinct indices in [2, 3, 5, 1, 4] satisfy a[k] = a[i] + a[j], counting each unordered pair {i, j}…
- What is the length of the longest prefix of the string ababbaba that is itself a palindrome?
- An LRU cache of capacity 2 receives the request sequence 2, 1, 2, 3, 1, 2. A request is a hit if its key is cached. How many hits occur?
- How many integers i with 1 <= i <= 50 have i i mod 10 = 9?
- How many integers in the range 1 to 100 are coprime to 30 (that is, gcd(x, 30) = 1)?