Trie | (Insert and Search)
Medium Accuracy: 68.83% Submissions: 8026 Points: 4

Trie is an efficient information retrieval data structure. Use this data structure to store Strings and search strings. Your task is to use TRIE data structure and search the given string A. If found print 1 else 0.

Example 1:

N = 8
key[] = {the,a,there,answer,any,by,
search = the
Output: 1
Explanation: the is present in the given
string "the a there answer any by bye

Example 2:

N = 8
key[] = {the,a,there,answer,any,by,
search = geeks
Output: 0
Explanation: geeks is not present in the
given string "the a there answer any by
bye their"

Your Task:
Complete insert and search function and return true if key is present in the formed trie else false in the search function. (In case of true, 1 is printed and false, 0 is printed by the driver's code.

Expected Time Complexity: O(M+|search|).
Expected Auxiliary Space: O(M).
M = sum of the length of all strings which is present in the key[] 

|search| denotes the length of the string search.

1 <= N <= 104
1 <= |input strings|, |A| <= 100

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.

to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.

Trie | (Insert and Search)

Output Window