Several boxes are placed in a row. Each box is one of three colors. We want to rearrange these boxes in a such way that no three consecutive boxes are of the same color. This process should affect the fewest boxes possible. More formally, we want to achieve the desired configuration by swapping pairs of boxes, and we want to maximize the number of boxes that are never moved.
You will be given a String boxes which describes the colors of the boxes. Colors are given as characters 'A', 'B' and 'C' respectively. Rearrange the boxes as described above and return the maximum possible number of boxes that are never moved. Return -1 if it is not possible to achieve the desired configuration.
|