Data Structures & AlgorithmsHardCodeforces Div2 C · TCS NQT
Let P[0] = 0 and P[k] be the XOR of the first k elements of [3, 5, 6, 3, 1, 5, 2]. How many pairs of indices (i < j) among 0..7 have P[i] = P[j]?
- A. 4
- B. 1
- C. 2
- D. 28
Correct answer: C. 2
Equal prefix XORs P[i] = P[j] mean that the XOR of the subarray a[i..j−1] is 0. Count equal values in the prefix list with a hash map. Forgetting P[0] = 0 removes one of the pairs.
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
- In how many ways can the binary string "0110100110" be cut into one or more contiguous segments so that every segment contains equally…
- Among all arrangements reachable from [4, 2, 1, 3] by swapping ONE pair of adjacent elements (or by doing nothing), what is the minimum…
- What is the minimum number of single-character flips needed to make "1101001011" alternate (no two adjacent characters equal)?
- What is the maximum sum of a contiguous subarray of [3, -2, 7, 1, -5, 4, 8, -1, 2] whose length is between 2 and 4 inclusive?
- How many strings of length 5 over the alphabet {0, 1, 2} have a digit sum divisible by 3 (the sum of their digit values)?
- A robot moves from the top-left to the bottom-right of a 4 × 5 grid of cells, each step going right, down, or diagonally down-right. How…