Data Structures & AlgorithmsHardCodeforces Div2 B-D · ICPC regional
What is the sum of Hamming distances (number of differing bit positions) over all unordered pairs of [1, 3, 5, 7]?
- A. 8
- B. 10
- C. 6
- D. 16
Correct answer: A. 8
Summing popcount(x XOR y) over all six unordered pairs gives the total. The column method (for each bit, count of ones times count of zeros) gives the same total.
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 [12, 4, 12, 4, 12, 4, 9] every value appears three times except one value that appears once. Which value appears once?
- What is the maximum value of a[i] XOR a[j] over index pairs i < j in [3, 10, 5, 25, 2, 8]?
- How many index pairs i < j in [6, 1, 8, 7, 3, 4] have a[i] AND a[j] = 0?
- How many times does the pattern "ababa" occur in the text "ababcababa", counting overlapping occurrences?
- How many palindromic substrings (counting each occurrence by position, length 1 and up included) does "abacaba" contain?
- What is the length of the longest well-formed (balanced) contiguous substring of ")()())"?