I have tried to implement without trie, but did not get the desired result. Can anyone please help.
Hello @anon70990627. Here are a few bugs I found:
-
check():@line 25- Sinceris negative, you’re accessing characters at negative indices ofstr1andstr2. Maybe you meant:
while(i<m && r>=-m && s1[i]==s2[i] && s1[s1.length()+r]==s2[s2.length()+r]){
-
solve():@line 79- I’m sorry, I don’t quite understand how you’re intending to usemap mobecause you’re losing the contribution of the previous value which had keykevery time a pair pops up with the same value askand I don’t see it getting resolved. -
solve():@line 91- Sinceset seis initially empty, theifcondition will always evaluate tofalse. So,answill contain nothing but the contribution of the pairs of equal strings. Maybe you meant:
if(se.find(it->second.first)==se.end() and se.find(it->second.second)==se.end()){
Here's a testcase where your program produces an incorrect result
It taking advantage of bug number 2
5
ab
acb
adcdb
asfaffb
aergwhrb
Your program produces:
1
The response should be:
2
Hope this was helpful. 
1 Like