# HackerRank : Week of Code 25 – Append and Delete

By | November 2, 2016

You have a string, , of lowercase English alphabetic letters. You can perform two types of operations on :

1. Append a lowercase English alphabetic letter to the end of the string.
2. Delete the last character in the string. Performing this operation on an empty string results in an empty string.

Given an integer, , and two strings, and , determine whether or not you can convert to by performing exactly of the above operations on . If it’s possible, print Yes; otherwise, print No.

Input Format

The first line contains a string, , denoting the initial string.
The second line contains a string, , denoting the desired final string. The third line contains an integer, , denoting the desired number of operations.

Constraints

• and consist of lowercase English alphabetic letters.

Output Format

Print Yes if you can obtain string by performing exactly operations on ; otherwise, print No.

Sample Input 0

hackerhappy
hackerrank
9


Sample Output 0

Yes


Explanation 0

We perform delete operations to reduce string to hacker. Next, we perform append operations (i.e., r, a, n, and k), to get hackerrank. Because we were able to convert to by performing exactly operations, we print Yes.

Sample Input 1

aba
aba
7


Sample Output 1

Yes


Explanation 1

We perform delete operations to reduce string to the empty string (recall that, though the string will be empty after deletions, we can still perform a delete operation on an empty string to get the empty string). Next, we perform append operations (i.e., a, b, and a). Because we were able to convert to by performing exactly operations, we print Yes.

Solution

Test case 2 and 3 are not passing. other than that, my approach is able to pass all
test cases for now.

If s and t are equal, and k is even, then output is Yes.
In else, I have checked the common index within both strings till which they are
same.

If both strings are not at all same, check if k is greater than the combined length
of s and t, then the output is yes , else its no.

if they are partially equal from start then ,
check if k is greater than the combined length of s and t, then the output is yes,
else its no.
check if k is exactly equal to the addition of number of different variables in s
and t together, else the output will be no.