Two strings M and W are given, need to check if one is subsequence of another.
I tried the following:
def filterr(bigStr,smallStr,i):
res=''
for char in bigStr:
if(char in smallStr[i:]):
i+=1
res+=char
return res
m,w=input().split()
if(m==w):
print('YES')
else:
if(len(m)<len(w)):
m,w=w,m
s=filterr(m,w,0)
if(s==w): print('YES')
else: print('NO')
I don't understand what is wrong with my above code. It's not working for some unknown testcases (on a coding site). I have tried all types of inputs that I can think of and it is giving the correct answer for all of them. Examples:
i/p: "john johanna" o/p: YES
i/p: "ira ira" o/p: YES
i/p: "kayla jayla" o/p: NO
Please help in finding why my code is not working for some unknown testcases.