# Beautiful String

Contributed by
Ankit Kharb
Easy
0/40
18 mins
70 %
+3 more

## Problem Statement

#### Your task is to determine the minimum number of operations Ninja should perform to make βSTRβ beautiful.

##### For Example :
``````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.
``````
Detailed explanation ( Input/output format, Notes, Images )
##### Constraints :
``````1 <= T <= 100
2 <= |STR| <= 10^5
STR[i] = β1β or β0β

Where '|STR|' denotes the length of βSTRβ.

Time Limit: 1 sec
``````

#### Sample Input 1 :

``````2
0000
1010
``````

#### Sample Output 1 :

``````2
0
``````

#### Explanation of Sample Input 1 :

``````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.
``````

#### Sample Input 2 :

``````2
01011
1001
``````

#### Sample Output 2 :

``````1
2
``````

#### Explanation of Sample Input 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.
``````
Autocomplete
Console