Data Structures & AlgorithmsModerateICPC regional · Amazon SDE OA

What is the minimum number of single-character flips needed to turn the binary string "10100101" into a string of the form 0...01...1 (all 0s then all 1s)?

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

Correct answer: C. 3

Try each split point k: zeros before it and ones after it, and count mismatches. The minimum over k is the answer; a prefix-count formula gives the same result.

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

Exams that ask this topic