public String reverse1(String str) {

        char chars[] = str.toCharArray();
        int forward = 0;
        int backward = chars.length - 1;
        boolean forwardReady = false;
        boolean backwardReady = false;

        while (forward < backward) {

            if (forwardReady && backwardReady) {
                char temp = chars[forward];
                chars[forward] = chars[backward];
                chars[backward] = temp;
                forwardReady = false;
                backwardReady = false;
                forward ++;
                backward --;
                continue;
            }

            if (Character.isDigit(chars[forward]) && Character.getNumericValue(chars[forward]) % 3 == 0) {
                forwardReady = true;
            } else {
                forward ++;
            }

            if (Character.isDigit(chars[backward]) && Character.getNumericValue(chars[backward]) % 3 == 0) {
                backwardReady = true;
            } else {
                backward --;
            }

        }

        return new String(chars);
    }