All right, so probably really simple.
You are given a binary string, right?
So you only have digits of zero and one and you need to perform as few swaps as possible or flips flips
as possible.
One flip your you.
Some zero or one.
Basically some character.
And if it's a zero, you transform into one.
If it's a one transformer to zero.
You should perform minimal number of flips such that you won't have the subsequent zero one zero or
one zero one in the final string.
Pretty easy, right?
So maybe.
Maybe this maybe isn't.
Could be tricky.
So the thing is that.
Zero one zero or one zero one.
When I've seen this, I thought about him.
All right.
So it's clear that if I have a zero.
Then maybe I have a couple of zeros next, then I have some one and a couple of ones next, then I can't
have another zero and the same for one one one one one one zero zero zero.
And then I can't have another one.
So basically, all you have to do here is take into account two possible scenarios.
The first scenario is that in the end you are going to have the string zero zero zero zero that are
that zero.
And then from some point, one one.
One that that one.
That's the first scenario.
The second scenario, you start with one.
Right.
So it's all a matter of what is the first character?
If it's a one one one one that that one zero zero zero, that allows zero.
So this is all of it.
Right.
So what do we have to do?
Let's take the first scenario and the second scenario.
You can do it alone because it's exactly the same thing for the first scenario.
Basically, what happens is that I'm going to have all these zeros for the first, let's say a, B,
Characters'.
So the four speechwriter's are only zeros.
And then the next and minus speech characters are going to be ones.
Of course, you need to try out each and every piece possible.
Right.
You could have one zero two zero three zeros.
You're gonna try out each and every B.
In the range zero, n could be zero.
Could be n n for each.
B, you basically need to know the following thing.
Among the first.
So first.
B, Characters'.
How many ones do we have.
Because the ones from the first B characters are going to be flipped.
And then among the last and minus speechwriter's, how many, how many, how many zeros will we have.
Right.
Because these zeros need to be flipped in order to become one.
So basically you need how many ones from a prefix.
Plus how many zeros from a suffix.
Of course, in the second scenario, you're going to need how many zeros are in this first B and how
many ones are in these last and minus B, how do you do this?
Yeah.
Partial sums.
Why not.
You can count partial sums.
Right.
How many zeros or ones do I have in this prefix in the first.
I characters' or even two variables.
You can eat a rate for the whole string once and count how many zeros, how many ones.
And then you fix each and every point or B and while iterating with the pointer you count how many ones
and zeros are in the in this prefix in the first speechwriter's.
And then of course you subtract.
Right.
So pretty easy.
Right.
You can code it alone but just like.
Oh it's accepted.
So yay.
One more.
Extra.
Right.
So basically you can see what I did here.
Total zero.
Total one iterated once counted.
How many zeros.
How many ones.
And then I start off with the minimum between this because I take into account only zeros and only ones
for the string.
And then for each G.
Which was the B that we used in the explanation.
I just count how many zeros.
How many ones.
And then the two possible scenarios are here.