Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys

Problem: A binary string "1100101011" is to be changed so that it alternates (no two adjacent characters are equal). Each operation flips one bit. What is the minimum number of flips needed, over both possible alternating patterns?

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

Correct answer: A. 3

There are only two alternating targets, and each costs the number of mismatched positions; the answer is the smaller cost. Flipping only to match the first character is a common incomplete approach.

More Coding Interview Problems questions

Exams that ask this topic