Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

What is the minimum number of bit flips (in a and b combined) to make a OR b equal to c, for a = 2, b = 6, c = 5? (Flip single bits of a or b.)

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

Correct answer: D. 3

Compare bit by bit: where c has a 0 and a or b has a 1, that bit must be flipped, and where both a and b are 1 while c is 0 two flips are needed. The count sums these per-bit costs.

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

Exams that ask this topic