John is a marble collector. He keeps his marbles in boxes. He also likes to keep things in order.
One day, his younger brother was playing with the marbles. After he was done, he put all the marbles back in boxes, but he did it randomly, so certain boxes might now contain marbles of different colors. John wants him to regroup the marbles so that the grouping satisfies the following restrictions:
- At most one box, called the joker box, may contain marbles of different colors. We can choose any box as a joker box.
- Every box except the joker box must either be empty or only contain marbles of the same color.
- All marbles of the same color, except those in the joker box, must be in the same box. It's possible that all marbles of the same color are in the joker box.
You are given a String[] boxes, where the j-th digit of the i-th element is the number of marbles of color j in the i-th box. Return the minimal number of moves necessary to regroup the marbles, where each move consists of taking any number of marbles from one box (not necessarily of the same color) and putting them into another.
|