Malvika is peculiar about balloon colors
InterviewTime limit1sMemory limit1024 MB
Given a string of 'a' and 'b' characters, find the fewest characters to flip so that all characters match.
- Level
Easy1 of 10
- Topics
- String, Implementation
- Solved
- No attempts yet
Problem
Little Malvika is very particular about colors. For her birthday, her mom bought balloons to decorate the house, so she asked Malvika about her color preferences. Malvika likes only two colors, amber and brass. Her mom bought n balloons, and each one is either amber or brass. This information is given as a string s made only of the characters 'a' and 'b'. 'a' means the balloon is amber, and 'b' means it is brass.
When Malvika saw the balloons, she got angry because she wanted all of them to be the same color. In her anger, she painted some of the balloons the opposite color (amber ones brass, and brass ones amber) so that all the balloons matched. Find the minimum number of balloons that must be painted to make all of them the same color.
Input
The first line contains a single integer T, the number of test cases.
The first and only line of each test case contains a string s.
Output
For each test case, print one line containing an integer, the minimum number of flips required.
Constraints
1 ≤ T ≤ 100
1 ≤ n ≤ 100, where n is the length of the string s.
Hint
In the first example, you can change amber to brass or brass to amber. In both cases, both balloons will have the same color. So you need to paint 1 balloon, and the answer is 1.
In the second example, all the balloons are already the same color, so you do not need to paint any of them. The answer is 0.