forked from srgnk/HackerRank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappend-and-delete.py
More file actions
35 lines (28 loc) · 802 Bytes
/
append-and-delete.py
File metadata and controls
35 lines (28 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/python3
import sys
def appendAndDelete(s, t, k):
start = 0
ind = 0
to_del = 0
to_app = 0
while ind < len(s) and ind < len(t) and s[ind] == t[ind]:
ind += 1
start = ind
if start < len(s):
to_del = len(s[start:])
if to_del == len(s) and k - to_del >= len(t):
return 'Yes'
if start < len(t):
to_app = len(t[start:])
k -= to_del + to_app
#print("start = {} to_del = {} to_app = {} k = {}".format(start, to_del, to_app, k))
if k == 0 or (k > 0 and k % 2 == 0) or k >= 2*len(t):
return 'Yes'
else:
return 'No'
if __name__ == "__main__":
s = input().strip()
t = input().strip()
k = int(input().strip())
result = appendAndDelete(s, t, k)
print(result)