### PROBLEM LINK:

[Practice][1]

[Contest][2]

**Author:** [Sunny Aggarwal][3]

**Tester:** [Sergey Kulik][4]

**Editorialist:** [Mugurel Ionut Andreica][5]

### DIFFICULTY:

CAKEWALK

### PREREQUISITES:

None

### PROBLEM:

Chef has **N** rooms, each of them painted in one of 3 colors (R, G or B). He wants to repaint the minimum number of rooms such that, in the end, all the rooms have the same color.

### QUICK EXPLANATION:

Paint all the rooms in the color which appears the largest number of times (of course, rooms which already have that color will not be repainted).

### EXPLANATION:

Repainting the minimum number of rooms is equivalent to **not** repainting (i.e. keeping the initial color in) the maximum number of rooms. Since all the rooms must have the same color in the end, this means that we should find the color **C** in which the most rooms are painted and then repaint all the rooms which have a color other than **C** in color **C**.

In order to count how many rooms of each color we have, we can simply maintain three variables **cntR**, **cntG** and **cntB**. Then we traverse the string denoting the colors of the rooms and increment the corresponding variable depending on the color denoted by the current character in the string.

Time complexity: **O(N)**.

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

Author’s solution can be found here.

Tester’s solution can be found here.

[1]: http://www.codechef.com/problems/COLOR

[2]: http://www.codechef.com/APRIL16/problems/COLOR

[3]: http://www.codechef.com/users/ma5termind

[4]: http://www.codechef.com/users/xcwgf666

[5]: http://www.codechef.com/users/mugurelionut

[6]: X

[7]: Y