blob: 404a9897d41edb90f9ed083d670481c42ae31a56 (
plain)
1
2
3
4
5
6
7
8
9
10
11
|
def make_flip(ch):
return '1' if (ch == '0') else '0'
def get_flip_with_starting_charcter(str, expected):
flip_count = 0
for i in range(len( str)):
if (str[i] != expected):
flip_count += 1
expected = make_flip(expected)
return flip_count
def min_flip_to_make_string_alternate(str):
return min(get_flip_with_starting_charcter(str, '0'),get_flip_with_starting_charcter(str, '1'))
|