Digital Dictionary RunError

The sample test cases give correct ans but after submitting there is run error.
https://ide.codingblocks.com/s/105652 This is link to my code. Please help in finding the mistake.

Hello @yfulwani82,

You have missed an important part in your code i.e.
Output Format:
If word with prefix exists in the database, then you need to print all the words with the given prefix in lexicographical order in separate lines else you need to print No suggestions

Also, it is not mentioned in the problem but you have to insert the prefix into the trie dictionary if it is not present in the trie while searching.
After printing No suggestions, call addWord(string word) function.

Implement the above mentioned modifications in your code.
If you still face issue, send me the updated code.

Give a like, it works perfectly.

Please explain why it is necessary to use a vector. For lexographical order I used a map instead of unordered_map. And why the code gives run error. It can show wrong ans or TLE.

The runtime error in your code was not coming because of the lexicographical order or the way you have implemented that logic.

The runtime error was coming due to an unpredictable behavior of addWord() function in the following part of your code.
It is working perfectly at the time of creating the trie dictionary.
But, causing runtime error if i modify the trie later for an unidentified prefix string.
if(!ans){
cout<<“No suggestions”<<endl;
t.addWord(s); //removing this is causing no error, but producing wrong answer.
}

If you want i can make your code run without using vector.