You have a string, , of lowercase English alphabetic letters. You can perform two types of operations on :
- Append a lowercase English alphabetic letter to the end of the string.
- 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
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.
- and consist of lowercase English alphabetic letters.
Yes if you can obtain string by performing exactly operations on ; otherwise, print
Sample Input 0
hackerhappy hackerrank 9
Sample Output 0
We perform delete operations to reduce string to
hacker. Next, we perform append operations (i.e.,
k), to get
hackerrank. Because we were able to convert to by performing exactly operations, we print
Sample Input 1
aba aba 7
Sample Output 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). Because we were able to convert to by performing exactly operations, we print
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.