Data Structures & AlgorithmsVery hardCodeforces Div2 B-D · ICPC regional
For the array [6, 12, 5, 8], what is the sum of (x & -x) over all elements x, where x & -x is the lowest set bit of x?
- A. 15
- B. 16
- C. 19
- D. 14
Correct answer: A. 15
x & -x isolates the lowest set bit: 6 gives 2, 12 gives 4, 5 gives 1, 8 gives 8, total 15. x & (x - 1) clears the lowest set bit, a different quantity.
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 [1, 2, 4, 3, 6] have a bitwise OR equal to exactly 7?
- How many distinct non-empty substrings does the string "abacaba" have?
- In the string "ababababa", how many times does "aba" occur, counting overlapping occurrences?
- For the string "aabaaab", what is the last value of the KMP prefix-function (the length of the longest proper prefix that is also a suffix…
- What is the smallest period p (1 <= p < n) of the string "abcabcabca" such that s[i] = s[i + p] for all valid i?
- Using the standard convention z[0] = 0, what is the sum of the Z-function values z[1] through z[6] of the string "aaabaab"?