Give test cases for which wrong

Hey Sparsh!
when no word exists with given prefix then instead of printing “No suggestions”, print nothing and insert that prefix into your trie


updated code wo map isliye use kiya taki lexicographically sahi aaye aab tle kyu aa rha h?

It should be because of use of unordered_map!
use an array of size 26 instead as characters belongs to [a,z]
Also don’t use map! things can be done without using a map as well.

without map if i print then guarantee nhi h ki lexo sort aaye

if you do dfs in order, its guaranteed that output is sorted!


for input:
4
pet
peter
rat
rack
5
rpet
pet
r
rac
rat

For this use of array is necessary! (instead of unordered_map)

if we write only map instead of unordered_mao then it is in order cant be this better way.


bhai ismein changes kar ke bata do mujhe nhu aa rh samjh

See what I’m trying to say is that you use array instead of unordered_map!
let it be
node *children[26];
mark every value as NULL initially,
insert/search operation follows as ((temp->children[s[i]-‘a’]))
now when you do dfs then it is guaranteed to be sorted as you visit from 0 to 25 (or ‘a’ to ‘z’)
try to implement this.
If you still face problem then I can share my code for reference in which I implemented same.
problems with map is increased time complexity!

not able to code after trying can u help.

https://ide.codingblocks.com/s/279665
take a look at it!

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.