← Back to challenges

Converting One Binary String to Another

PythonHardstringslogicrecursionloops

Instructions

Write a function that returns the minimum number of swaps to convert the first binary string into the second.

Examples

min_swaps("1100", "1001") ➞ 1

min_swaps("110011", "010111") ➞ 1

min_swaps("10011001", "01100110") ➞ 4

Notes

  • Both binary strings will be of equal length.
  • Both binary strings will have an equal number of zeroes and ones.
  • A swap is switching two elements in a string (swaps do not have to be adjacent).
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Format VII: Truncating Strings