Login

All Problems

Problem title

Difficulty

Avg time to solve

LCA of three Nodes

Easy

20 mins

Sum Of Infinite Array

Moderate

35 mins

Pair Sum

Easy

15 mins

Sum or Product

Easy

15 mins

Yogesh And Primes

Moderate

20 mins

Find Duplicate in Array

Easy

15 mins

Beautiful String

Easy

18 mins

Reverse The Array

Easy

15 mins

Longest Univalue Path

Moderate

10 mins

Sort 0 1 2

Easy

22 mins

Problem

Submissions

231

Avg. time to solve

18 min

Success Rate

70%

Problem Statement

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

Console

Sample Test Case

Custom Test Case

Download Test Cases

Test Case 1

Test Case 2

Test Case 3

Saving Code...

Full Screen Mode

Change Language

Change Theme

Solution submission not allowed

Save Code

Reset Code