Maximum Flips in a Binary String to Make All 1’s in Left and All 0’s in Right

Given a binary string, we can flip all 1s and 0s . Calculate the minimum flips required to make all 1s in left and all 0s in right. There should be at least one 0 and one 1.


"1011000" can be turned into "11110000" with 1 flip.

"00001" can be turned into "10000" with 2 flips.

Contributed by Berkan Teber