• + 0 comments

    This is my solution. It's in python. It's probably a bit over complicated but I'll post it anyway

    def appendAndDelete(s, t, k):

    s_list = list(s)
    t_list = list(t)
    changes_needed = 0
    last_the_same = True
    
    if s == t:
        print("Yes")
        return "Yes"
    
    for i in range(len(s)):
        if i < len(t):
            if s[i] == t[i]:
                if last_the_same is False:
                    changes_needed += 1
                else:
                    print(s[i] , " = ", t[i])
            else:
                changes_needed += 1
                last_the_same = False
        else:
            changes_needed += 1
    
    if(changes_needed > 0):
        del s_list[-changes_needed:]
    
    print(" removing from s = ", s_list, ", now adding t... we will add: ", t_list[-changes_needed: ])
    
    for i in range(len(t)):
    
        if i < len(s_list):
            if s_list[i] != t_list[i]:
                s_list.append(t_list[i])
                changes_needed += 1
        else:
            s_list.append(t_list[i])
            changes_needed += 1
    
    
    print(" s with t added = ", s_list, " the number of changes needed was :", changes_needed)
    
    print("k - changes_needed = ", k - changes_needed, ", s_list = ",s_list, ", t_list = ", t_list )
    
    
    if s_list == t_list:
        if len(s) >= len(t):
            if (k - changes_needed) == 0 or (k - changes_needed) > 1:
                print('Yes')
                return "Yes"
            else:
                print('No')
                return "No"
        else:
            if (k - changes_needed) == 0 or (k - changes_needed) % 2 == 0:
                print('Yes')
                return "Yes"
            else:
                print('No')
                return "No"
    else:
        print('No')
        return "No"