Skip to content

Files

Latest commit

2bb40cf · Oct 26, 2018

History

History

EqualizingBitStrings

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Oct 26, 2018
Oct 26, 2018

EqualizeBitStrings

You are given two binary strings a and b of the same length. You can perform the following two operations on the string a:

  • Swap any two bits at indices i and j respectively (1 ≤ i, jn), the cost of this operation is |i−j|, that is, the absolute difference between i and j.
  • Select any arbitrary index i (1 ≤ in) and flip (change 0 to 1 or 1 to 0) the bit at this index. The cost of this operation is 1.

Find the minimum cost to make the string a equal to b. It is not allowed to modify string b.