https://www.acmicpc.net/problem/1439
It is a decision making greedy q like https://velog.io/@whitehousechef/%EB%B0%B1%EC%A4%80-2012%EB%B2%88-%EB%93%B1%EC%88%98-%EB%A7%A4%EA%B8%B0%EA%B8%B0 the buying and selling stock q
To decide whether to flip 0 or 1, we count how many "regions" of consecutive 0s or 1s there are in a given string and choose that minimum. For example,
11101101 There are 3 regions of 1s and 2 regions of 0s so it we should flip 0s to 1 cuz we can do that in 2 moves whereas for vice versa we need 3 moves.
Then how should we count number of 0s and 1s along the way? I first thought of 2 variables - count0 and count1 but we won't know how to update this variables when lst[i] comes as iteration. So I thought for a bit and used an ans list of [0,0] and we can get the index, which would be either 0 or 1 and update the count, which is gna be stored in this list.
yea just count the number of regions but i think you can use 2 variables, so my initial explanation is wrong.
but this [0,0] is a cleaner way.
lst = input()
ans = [0,0]
tmp=lst[0]
ans[int(tmp)]+=1
for i in range(1,len(lst)):
if lst[i]!=tmp:
ans[int(lst[i])]+=1
tmp=lst[i]
else:
continue
print(min(ans))
n time and space