# getting wrong answer for problem chef and wild card matching in beginner practice

for _ in range(int(input())):
s1=input()
s2=input()
i,p=0,0
while i<len(s1):
if s1[i]==’?’ or s2[i]==’?’:

``````		i+=1
continue
elif s1[i]==s2[i]:
p=1
i+=1
continue
else:
p=0
i+=1
break
i+=1
if p==0:
print('No')
else:
print('Yes')``````

Put `p=1` inside first `if` block as well. Because currently, you are ignoring the case where any string starts with ‘?’ itself without any matching characters in the beginning. For example, if X = “a?” and Y = “??” your code gives NO where as it should have been YES. Below version of your code works:

``````for _ in range(int(input())):
s1=input()
s2=input()
i,p=0,0
while i<len(s1):
if s1[i]=='?' or s2[i]=='?':
p=1   # you were missing this line
i+=1
continue
elif s1[i]==s2[i]:
p=1
i+=1
continue
else:
p=0
i+=1
break
i+=1
if p==0:
print('No')
else:
print('Yes')``````
1 Like

1.Run the for loop from [0…len] where len is the length of the strings.
If both s[i] and t[i] are not equal to ‘?’, you check if they are equal or not. If they are not equal, then you know that the answer is a “No”.
2. If you have reached the end of the string and all characters match, then the answer is “Yes”.

Note:

1. There maybe a case where in s[i]==’?’ and t[i] is some character between a-z or vice versa. This case is acceptable and is handled by the above algorithm (in fact it doesnt bother such cases. ).

Please look at my solution for better understanding.

Good luck.

thanks man

//