question–>
https://practice.geeksforgeeks.org/problems/trie-insert-and-search0651/1#
code–>
void insert(struct TrieNode *root, string key) {
// code here
struct TrieNode* temp=root;
for(int i=0;key[i]!='\0';i++){
char ch=key[i];
if(temp->children[ch-'a']==NULL){
struct TrieNode* child=getNode();
temp->children[ch-'a']=child;
}
else{
temp=temp->children[ch-'a'];
}
}
temp->isLeaf=true;
}
// root : root node of the trie
// key : string to search in the trie
// Returns true if key presents in trie, else false
bool search(struct TrieNode *root, string key) {
// code here
struct TrieNode* temp=root;
for(int i=0;key[i]!='\0';i++){
char ch=key[i];
if(temp->children[ch-'a']!=NULL){
temp=temp->children[ch-'a'];
}
else{
return false;
}
}
return temp->isLeaf;
}
Not passing all testcases help!!