Problem of the day
Minimum operations to make βSTRβ β0010β beautiful is β1β. In one operation, we can convert β0β at index β0β (0-based indexing) to β1β. The βSTRβ now becomes β1010β which is a beautiful string.
The first line contains an integer 'T' which denotes the number of test cases or queries to be run. Then the test cases follow.
The only line of each test case contains a binary string 'STR'.
For each test case, print the minimum operations needed to make βSTRβ beautiful.
Print the output of each test case in a separate line.
You are not required to print the expected output, it has already been taken care of. Just implement the given function.
1 <= T <= 100
2 <= |STR| <= 10^5
STR[i] = β1β or β0β
Where '|STR|' denotes the length of βSTRβ.
Time Limit: 1 sec
2
0000
1010
2
0
For the first test case:
The two beautiful strings that can be formed from the given βSTRβ
are β1010β and β0101β. Ninja can transform βSTRβ to β1010β by
performing the following operations:
Replace β0β at index 0 by β1β.
Replace β0β at index 2 by β1β.
Ninja can transform βSTRβ to β0101β by performing the following
operations:
Replace β0' at index 1 by β1β.
Replace β0β at index 3 by β1β.
The minimum number of operations in transforming βSTRβ to either of the two beautiful strings is 2.
For the second test case:
Given βSTRβ is already beautiful so the minimum number of operations required is 0.
2
01011
1001
1
2
For the first test case:
The two beautiful strings that can be formed from the given βSTRβ are β10101β and β01010β. Ninja can transform βSTRβ to β10101β by performing the following operations:
Replace β0β at index 0 by β1β.
Replace β1β at index 1 by β0β.
Replace β0β at index 2 by β1β
Replace β1β at index 4 by β0β.
Ninja can transform βSTRβ to β01010β by performing the following operations:
Replace β1β at index 4 by β0β.
The minimum number of operations in transforming βSTRβ to beautiful is the minimum of the above two which is 1.
For the second test case:
The two beautiful strings that can be formed from the given βSTRβ are β1010β and β0101β. Ninja can transform βSTRβ to β1010β by performing the following operations:
Replace β0β at index 2 by β1β.
Replace β1β at index 3 by β0β.
Ninja can transform βSTRβ to β0101β by performing the following operations:
Replace β0β at index 0 by β1β.
Replace β1β at index 1 by β0β.
The minimum number of operations in transforming βSTRβ to either of the two beautiful strings is 2.