Skip to content

Commit 0a961a8

Browse files
authored
Create Append and Delete.py
1 parent 05924fe commit 0a961a8

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

Append and Delete.py

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
'''
2+
Problem Statement: https://www.hackerrank.com/challenges/append-and-delete/problem
3+
@Coded by TSG,2020
4+
'''
5+
6+
#!/bin/python3
7+
8+
import math
9+
import os
10+
import random
11+
import re
12+
import sys
13+
14+
# Complete the appendAndDelete function below.
15+
16+
def appendAndDelete(s, t, k):
17+
S=list(s)
18+
T=list(t)
19+
20+
m,mm=len(S),len(T)
21+
min_len=min(m,mm)
22+
23+
c = min_len
24+
25+
for i in range(c):
26+
if S[i] != T[i]:
27+
break
28+
c=i
29+
op = m + mm - (2 * c)
30+
31+
if ((k == op) or (k >= len(s) + len(t)) or (k >= op and (k - op) % 2 == 0)):
32+
return ("Yes")
33+
34+
else:
35+
return("No")
36+
37+
38+
39+
if __name__ == '__main__':
40+
fptr = open(os.environ['OUTPUT_PATH'], 'w')
41+
s = input()
42+
t = input()
43+
k = int(input())
44+
45+
result = appendAndDelete(s, t, k)
46+
47+
fptr.write(result + '\n')
48+
fptr.close()

0 commit comments

Comments
 (0)