• + 10 comments

    Quite a compact solution in Python.

    Basically, I remove characters from the end of s until t starts with s and the number of missing characters to get to t is the number of operations left. I also break if there are no more operations or if s became empty. Afterwards I simply check whether I have enough operations left to add character to s to reach t.

    #!/bin/python
    
    import sys
    
    
    s = raw_input().strip()
    t = raw_input().strip()
    k = int(raw_input().strip())
    for ops_left in reversed(range(1, k + 1)):
        if s == t[:len(s)] and len(t) - len(s) == ops_left or len(s) == 0:
            break
        s = s[:-1]
    print "Yes" if len(t) - len(s) <= ops_left else "No"