Data Structures & AlgorithmsModerateCodeforces Div 2 C · ICPC regional

What is the minimum number of single-bit flips needed to change the 8-bit number 13 into the 8-bit number 22?

  1. A. 5
  2. B. 3
  3. C. 4
  4. D. 1

Correct answer: C. 4

Only bits where the two numbers differ need flipping, so the answer is the popcount of 13 XOR 22. Counting differences in AND or OR bits uses a different expression and gives another value.

More Coding Interview Problems questions

Exams that ask this topic