public int palindromify(String pal, String read) {
    StringBuilder sb = new StringBuilder(read);
    int insertions = 0; //track insertions
    int palIndex = 0; //our progress through the palindrome
    //caches characters we know aren't further in the input, saves time
    Set<Character> none = new HashSet<>();
    boolean outOfInput = false;
    for (int i = 0;; i++) {
        if (i >= sb.length()) {
            outOfInput = true; //if we run out of input, we know we have to append remainder
            break;
        }
        if (palIndex >= pal.length()) {
            sb.delete(i, sb.length()); //remove remainder, we're out of palindrome
            break;
        }
        char curr = pal.charAt(palIndex++); //increment palindrome
        if (sb.charAt(i) != curr) {
            //perform lookahead
            boolean found = false;
            if (!none.contains(curr)) { //only search a missing char once
                for (int w = i + 1; w < sb.length(); w++) {
                    if (sb.charAt(w) == curr) {
                        sb.replace(i, w + 1, "" + curr); //replace up to our lookahead
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    none.add(curr);
                }
            }
            if (!found) {
                //simply insert our character, later ones are useful for others
                sb.insert(i, curr);
                insertions++; //this was an insertion, one of our counted values
            }
        }
    }
    //if we ran out of input, append the rest of palindrome
    return insertions + (outOfInput ? pal.length() - sb.length() : 0);
}
This saves you a lot of copying/iteration/needless work, and should ensure that the max