# Malvika is peculiar about color of balloons Codechef Solution

#### ByBrokenprogrammers

Dec 12, 2022

Hello Programmers In this post, you will know how to solve the Malvika is peculiar about color of balloons Codechef Solution.

One more thing to add, don’t directly look for the solutions, first try to solve the problems of Codechef by yourself. If you find any difficulty after trying several times, then you can look for solutions.

### Problem

Little Malvika is very peculiar about colors. On her birthday, her mom wanted to buy balloons for decorating the house. So she asked her about her color preferences. The sophisticated little person that Malvika is, she likes only two colors — amber and brass. Her mom bought n balloons, each of which was either amber or brass in color. You are provided this information in a string s consisting of characters ‘a’ and ‘b’ only, where ‘a’ denotes that the balloon is amber, where ‘b’ denotes it being brass colored.

When Malvika saw the balloons, she was furious with anger as she wanted all the balloons of the same color. In her anger, she painted some of the balloons with the opposite color (i.e., she painted some amber ones brass and vice versa) to make all balloons appear to be the same color. As she was very angry, it took her a lot of time to do this, but you can probably show her the right way of doing so, thereby teaching her a lesson to remain calm in difficult situations, by finding out the minimum number of balloons needed to be painted in order to make all of them the same color.

### Input

• The first line of input contains a single integer T, denoting the number of test cases.
• The first and only line of each test case contains a string s.

### Output

• For each test case, output a single line containing an integer — the minimum number of flips required.

### Constraints

• 1 ≤ T ≤ 100
• 1 ≤ n ≤ 100, where n denotes to the length of the string s.

### Example

```Input:
3
ab
bb
baaba
Output:
1
2
```

### Explanation

In the first example, you can change amber to brass or brass to amber. In both the cases, both the balloons will have same colors. So, you will need to paint 1 balloon. So the answer is 1.

In the second example, As the color of all the balloons is already the same, you don’t need to paint any of them. So, the answer is 0

### Malvika is peculiar about color of balloons CodeChef Solution in JAVA

```import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
for(int i=0;i<n;i++){
String s=sc.next();int a=0,b=0;
for(int j=0;j<s.length();j++){
if(s.charAt(j)=='a') a++;
else b++;
}
if(a<b) System.out.println(a);
else System.out.println(b);
}
}
}
```

### Malvika is peculiar about color of balloons CodeChef Solution in CPP

```#include <bits/stdc++.h>
using namespace std;
int main(){
int t;cin>>t;
for(;t!=0;t--){
string s;cin>>s;
int numA = (int) count(s.begin(),s.end(),'a');
int numB=(int) count(s.begin(),s.end(),'b');
cout<<(numB>numA?numA:numB)<<endl;
}
}
```

Disclaimer: The above Problem (Malvika is peculiar about color of balloons) is generated by CodeChef but the solution is provided by BrokenProgrammers. This tutorial is only for Educational and Learning purpose.

Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.