


1) Trie(): Ninja has to initialize the object of this “TRIE” data structure.
2) insert(“WORD”): Ninja has to insert the string “WORD” into this “TRIE” data structure.
3) countWordsEqualTo(“WORD”): Ninja has to return how many times this “WORD” is present in this “TRIE”.
4) countWordsStartingWith(“PREFIX”): Ninjas have to return how many words are there in this “TRIE” that have the string “PREFIX” as a prefix.
5) erase(“WORD”): Ninja has to delete one occurrence of the string “WORD” from the “TRIE”.
1. If erase(“WORD”) function is called then it is guaranteed that the “WORD” is present in the “TRIE”.
2. If you are going to use variables with dynamic memory allocation then you need to release the memory associated with them at the end of your solution.
The first line contains a single integer “T” representing the number of test cases.
The first line of each test case will contain a single integer “N” which denotes how many times the functions(as discussed above) will be called.
The next “N” lines contain the two space-separated strings, the first one is the name of the function and the second one is a “WORD”.
For each test case, complete all the functions as we discussed above.
The output for every test case will be printed in a separate line.
You do not need to print anything; it has already been taken care of. Just implement the given function.
1 <= “T” <= 50
1 <= “N” <= 10000
“WORD” = {a to z}
1 <= | “WORD” | <= 1000
Where “T” is the number of test cases, “N” denotes how many times the functions(as discussed above) we call, “WORD” denotes the string on which we have to perform all the operations as we discussed above, and | “WORD” | denotes the length of the string “WORD”.
Time limit: 1 sec.
First, we declare a “TRIE” class/struct. In this “TRIE” class/struct there are three fields.
In this function, we add this ‘WORD” into this “TRIE” data structure.
In this function, we count how many times this word is present in this “TRIE”.
In this function, we count how many words are present in this “TRIE” those having prefix is equal to "PREFIX".
In this function, we remove this word from “TRIE”.
Reference: https://www.codingninjas.com/blog/2020/09/22/using-trie-in-data-structures/
Complete String
Complete String
Complete String
Complete String
Complete String
Complete String
Similar Name
Similar Name
Similar Name
Similar Name
Auto Suggestion
Auto Suggestion
Auto Suggestion
Auto Suggestion
Auto Suggestion
Auto Suggestion
Palindrome Pairs
Design Search Autocomplete System
Design Search Autocomplete System
Design Search Autocomplete System
Design Search Autocomplete System
Design Search Autocomplete System
Design Search Autocomplete System