public int maxWeightTransformationNoDPSol(char str1[], int i, int size) {
        // If the counter has gone past maximum size
        // of string, then return 0
        if (i > size)
            return 0;

        // If the counter is equal to the size of
        // string, then retun 1. Since, there is no point of string
        // transformation.
        if (i == size)
            return 1;

        // If pair is not made, weight gained is 1
        int res = 1 + maxWeightTransformationNoDPSol(str1, i + 1, size);

        // is pair is made
        if (i + 1 <= size) {
            if (str1[i] == str1[i
                    + 1]) {// if consecutive elements are same, weight gained is 3 after transformation
                res = Math.max(res, 3 + maxWeightTransformationNoDPSol(str1, i + 2, size));
            } else if (str1[i] != str1[i
                    + 1]) {// if consecutive elements are different,  weight gained is 4
                res = Math.max(res, 4 + maxWeightTransformationNoDPSol(str1, i + 2, size));
            }
        }

        return res;
    }
Brute Force Solution
str1[] : String array (str.toCharArray())
i: first index of string (0)
size: str.length() -1
src/algo/dp/MaxWeightTransformation.java