Error in ENGLISH

I have tried to implement without trie, but did not get the desired result. Can anyone please help.

Code

Hello @anon70990627. Here are a few bugs I found:

  1. check():@line 25 - Since r is negative, you’re accessing characters at negative indices of str1 and str2. Maybe you meant:
while(i<m && r>=-m && s1[i]==s2[i] && s1[s1.length()+r]==s2[s2.length()+r]){
  1. solve():@line 79 - I’m sorry, I don’t quite understand how you’re intending to use map mo because you’re losing the contribution of the previous value which had key k every time a pair pops up with the same value as k and I don’t see it getting resolved.

  2. solve():@line 91 - Since set se is initially empty, the if condition will always evaluate to false. So, ans will 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. :slight_smile:

1 Like