# CHN09 - Editorial

Contest

Author: ???
Tester: Kevin Atienza, Jingbo Shang
Editorialist: Kevin Atienza

Strings, loops

### PROBLEM:

Given a string consisting of `a`s and `b`s, what is the minimum number of letters to be changed so that all letters are the same?

### EXPLANATION:

Count the `a`s and `b`s, and print the smaller count. (There’s really nothing more to it.) To make all letters the same, they will either be all `a`s or all `b`s, so either all `b`s or all `a`s need to be changed. Since we want the minimum, the answer is the smaller one.

There are only very few non-AC verdicts for this problem, and the only mistakes are (1) compile errors and (2) failing to initialize the array (to contain the string) properly.

Compile errors are some of the most unproductive verdicts in a contest, because they can easily be discovered and fixed (by simply compiling the code!). Though there are no penalty points for compile errors, remember that this is a short contest, so saving a few units of time and effort helps.

Failing to initialize the array properly can happen in one of the following ways:

• By failing to initialize the array at all.
• By failing to allocate an array large enough to contain the input. Remember to look at the constraints to know how much you need to allocate. Remember that in C++, you need an array of length n+1 to store a string of length n, because strings should be terminated by a null character (’`\0`’).

This is mostly a C/C++ problem though. The simplest ways to take a string input in Java don’t involve allocating an array yourself, so this problem doesn’t happen.

This is the easiest problem in the contest, so you should try to spend little time to get this one AC’ed, to give you more time to solve the others.

O(n)

### AUTHOR’S AND TESTER’S SOLUTIONS:

[setter][333]
[tester][444]
[editorialist][555]

[333]: The link is provided by admins after the contest ends and the solutions are uploaded on the CodeChef Server.
[444]: The link is provided by admins after the contest ends and the solutions are uploaded on the CodeChef Server.
[555]: The link is provided by admins after the contest ends and the solutions are uploaded on the CodeChef Server.