Data Structures & AlgorithmsModerateTCS NQT · Infosys

Problem: What is the minimum number of bit flips needed to convert 29 into 15 (flips of single bits in binary)?

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

Correct answer: D. 2

The number of flips is the Hamming distance, the popcount of the XOR of the two numbers. Comparing decimal digits or differences gives a wrong count.

More Coding Interview Problems questions

Exams that ask this topic