• + 0 comments

    python

    def appendAndDelete(s, t, k):
        # Write your code here
        
        #all cases where the length of the two strings combined is less than or equal to k work
        if len(t) + len(s) <= k:
            return 'Yes'
        
        index=0
    		
        while True:
            
            #remove the out of index range scenario
            if index > len(s) - 1 or index > len(t) - 1:
                break
            #determine up to which index is the same
            if s[index] == t[index]:
                index+=1
            else:
                break
                
        #determine remaining steps needed and if the difference between remaining and k is either 0 or even
         
        remaining_steps = len(s) + len(t) - index * 2
        if remaining_steps <= k and (k - remaining_steps) % 2 == 0:
            return 'Yes'
        else:
            return 'No'