Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 B
What is the number of distinct values of a[i] XOR a[j] over all pairs i < j of the array [1, 2, 3, 4]?
- A. 6
- B. 7
- C. 1
- D. 12
Correct answer: A. 6
The six pair XORs are 3, 2, 5, 1, 6, 7, all different, so there are 6 distinct values. 7 is the largest XOR rather than a count, 1 is the smallest, and 12 counts ordered 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
- How many palindromic substrings does the string aabbaa contain (counted by position)?
- What is the number of distinct subsequences (including the empty one) of the string abab?
- Starting at value 1, apply the operations x -> 2x, then x -> x + 3, alternating (double, add 3, double, add 3, ...), for 6 operations in…
- A matrix has rows [1, 2, 3], [4, 5, 6], [7, 8, 9]. The matrix is transposed and then each row is reversed. What is the element in row 0…
- How many subsequences of length 3 of the string abcabc are palindromes (distinct index choices count separately)?
- A queue holds 1 to 6 in order. The front element is moved to the back, then the front is removed, repeated until one element remains…