Need help| ENGRIS - PROC2020| projectcode 2.0

hello every , i tried to solve ENGRIS using Trie ,but got WA.
will u plz help me with this?
my submitted code
works fine with given test case and with a bunch i tried with .
thanks a ton in advance…

import collections

class TrieNode:
    def __init__(self):
        self.char=collections.defaultdict(TrieNode)
        self.isEnd=False
        
class Trie:
    
    def __init__(self):
        self.root=TrieNode()
        
    def insert(self,word):
        curr=self.root
        for l in word:
            curr=curr.char[l]
        curr.isEnd=True
        
    def match(self,node,string):
        for l in string:
            node=node.char.get(l)
            if not node:
                return False
        return node.isEnd
        
        
        
        
    def isPresent(self,string):
        curr=self.root
        
        for l in range(len(string)):
            if string[l] in curr.char:
                curr=curr.char[string[l]]
            else:
                for ch in curr.char:
                    new=curr.char[ch]
                    if self.match(new,string[l:]):
                        return string[:l]+ch+string[l:]
                    elif self.match(new,string[l+1:]):
                        return string[:l]+ch+string[l+1:]
        if(curr.isEnd):
            return string
        for c in curr.char:
            if self.match(curr.char[c],""):
                return string+c


            
t=int(input())
for _ in range(t):
    t=Trie()
    
    
    n,q=map(int,input().split())
    for __ in range(n):
        t.insert(input())
    for ___ in range(q):
        print(t.isPresent(input()))
1 Like

See the following testcase:

1
47 1
nlnjwztghxhfzexsjwwemm
rkbmaodtoindglmnxrroqs
mzpsqdnsyujxfqgpzjfeut
airzsswsmaksugqvtfcbbx
dyphbmpusllcjbifhkhbuu
yqrdwgpggorbsqbnbkjoux
uhygesvvflnsjmxrmapalp
irljygjlfanzqagmoittmr
kqbqvtcstzkgktkwdjyxjv
fownzbkezpuwojfwfyoawt
jxaxotzfwhrowjdbylbwnr
rhxscmdiavpiyuarpfdkvv
phbqkeyircysmyqxdahfjn
xkamchizhuqoxocdusvxkw
mcgboxttqyntsxhqkkhbaq
svgpmxbkhfacmdjjyggsup
xrqqsmrtmgztwaxumnxzao
eqvntwwqtfgulcrnhtxisp
lpmhsrxspulfqmjfxwuiav
avgevjinhurjwuxzjnscns
vwglmqnymmorhipfjzhrki
dunvcxmnrvyitxjyejraqw
ajkbgenqmqhtiusqxfptme
qrqokafmiimvyrrgnxdvsh
zogcvkzuorlqypjylfyqah
asgpfwkfmgbnervfxolyoa
bpvjpcevtfzrdrhtsneokd
xfkvfixccqiyplqmaejjjj
ubcviqempsfczlmjhtimby
iekelfhpwwrtbzzjiwafof
xeczpiyjembacapcbonzff
sbydrfnwrtvqpcjzocuweo
stuxyhqouzjediziyqormk
qenmorehgzxslltzkdcfgt
hzqdgrevpgcqjmskrlkqop
plktjkytnaqximrflyqgzb
tptwbkgkwrthvslgtnwmaf
qkvkpepavoboyjouesvvat
afhowdgcstwosugadoyzxk
owiqgbgivsoltlkhhviraj
wbrjviytqemuxcoxbrsuis
xvclbvyutljimjwcbzzdlq
vtdexprkyykxuuyyldqxdr
rymlzayfrqfgvciihjjobf
jixakplpbdjupckargwgxt
ogprsolewsgkrngkznioqm
ilbhixyusstoqiqfiflolz
zpsqdnsyujxfqgpzjfeut

This outputs as None
Expected Output: mzpsqdnsyujxfqgpzjfeut

Hope this helps!

1 Like

Try this
1
1 1
a
a
Expected output : a
Your output : None

question says it contains exactly q words which differs from the original string.
"For each misspelt word in Sandy’s presentation, there exists one and only one correctly spelt word in your dictionary that corresponds to it. "
is it possible to have no error in a string ?
correct me if am wrong or if i misunderstood the question. @yatin_yk08
thanks .

thanks a lot brother @mohilllll ,going to debug it …i will let u know about my progress.

1 Like

It says you are given q queries, each string would be correct or misspelt, if correct simply print it, else find the correct string for it… :slightly_smiling_face:

my bad …
thanks @yatin_yk08

1 Like

brother edited the issue u mentioned is solved .
@yatin_yk08