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?

  1. A. 15
  2. B. 16
  3. C. 19
  4. 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.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic