• + 0 comments

    My Java 8 solution:

    public static String appendAndDelete(String s, String t, int k) {
        int numMoves = s.length() + t.length();
    
        for (int i = 0; i < s.length() && i < t.length() && s.charAt(i) == t.charAt(i); i++) {
            numMoves -= 2;
        } //see which letters they have in common
    
        if (numMoves > k || (t.length() > s.length() && (numMoves % 2 != 0))) {
            return "No"; //if more than k moves are required to achieve the string
        }
        return "Yes";
    
    }