Map approach with better time complexity doesnt work

try to implement it with trie

but with unordered map i did it with better complexity I just sorted the strings that is nlogn and all the queries are processed faster then tries so why doesn’t it work

image
this is not nlogn

Just go through trie videos and u can then refer https://ide.codingblocks.com/s/581976
if u face any difficulty

ya it would sum of length of string which is also in the range sum(len(stringi)) ≤ 2∗10^5 so also it is not giving a tle it is giving a wa so what is actually wrong please tell

ok so consider this input
6
app
apple
application
batman
batmobile
cat
7
ap
bat
batcave
bat
cat
appl
appledore

expected output is
app
apple
application
batman
batmobile
No suggestions
batcave // this is missing in ur o/p
batman
batmobile
cat
apple
application
No suggestions

secondly ur code is missing “No suggestions” statement line… read the question carefully.


this solution is similar to ur logic. but it will also not pass all test cases.
It is only failing cases where N is 10^5. So the issue might be due to memory limit exceeded or something which is not being shown. so i suggest u try implementing it by tries only although ur logic is ok.

1 Like

thanks for pointing out the mistakes

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.