public int countCoins(String state) {
        int count = 0;
        for (int i = 0; i < state.length(); i++) {
            if (i > 0 && !equalsToPreviousCoin(state, i)) {
                count++;
            } else if (i < state.length() - 1 && !equalsToNextCoin(state, i)) {
                count++;
            }
        }
        return count;
    }