I got the following problem for the Google Coding Challenge which happened on 16th August 2020. I tried to solve it but couldn't.
There are
Nwords in a dictionary such that each word is of fixed length andMconsists only of lowercase English letters, that is('a', 'b', ...,'z')
A query word is denoted byQ. The length of query word isM. These words contain lowercase English letters but at some places instead of a letter between'a', 'b', ...,'z'there is'?'. Refer to the Sample input section to understand this case.
A match count ofQ, denoted bymatch_count(Q)is the count of words that are in the dictionary and contain the same English letters(excluding a letter that can be in the position of?) in the same position as the letters are there in the query wordQ. In other words, a word in the dictionary can contain any letters at the position of'?'but the remaining alphabets must match with the query word.You are given a query word Q and you are required to compute
match_count.Input Format
- The first line contains two space-separated integers
NandMdenoting the number of words in the dictionary and length of each word respectively.- The next
Nlines contain one word each from the dictionary.- The next line contains an integer Q denoting the number of query words for which you have to compute match_count.
- The next
Qlines contain one query word each.Output Format
For each query word, printmatch_countfor a specific word in a new line.
Constraints1 <= N <= 5X10^4 1 <= M <= 7 1 <= Q <= 10^5
So, I got 30 minutes for this question and I could write the following code which is incorrect and hence didn't give the expected output.
def Solve(N, M, Words, Q, Query):
output = []
count = 0
for i in range(Q):
x = Query[i].split('?')
for k in range(N):
if x in Words:
count += 1
else:
pass
output.append(count)
return output
N, M = map(int , input().split())
Words = []
for _ in range(N):
Words.append(input())
Q = int(input())
Query = []
for _ in range(Q):
Query.append(input())
out = Solve(N, M, Words, Q, Query)
for x in out_:
print(x)
Can somebody help me with some pseudocode or algorithm which can solve this problem, please?


