We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
classTrie{public:Trie*childNodes[10];intwordCount;Trie(){for(inti=0;i<10;i++){childNodes[i]=NULL;}wordCount=0;}};boolinsert_key(Trie*root,stringkey_word){Trie*currentNode=root;for(inti=0;i<key_word.size();i++){intindex=key_word[i]-'a';if(currentNode->childNodes[index]==NULL){Trie*newNode=newTrie();currentNode->childNodes[index]=newNode;}else{if(currentNode->childNodes[index]->wordCount||i==key_word.size()-1){returnfalse;}}currentNode=currentNode->childNodes[index];}currentNode->wordCount++;returntrue;}voidnoPrefix(vector<string>words){Trie*root=newTrie();for(autoword:words){if(!insert_key(root,word)){cout<<"BAD SET \n"<<word;return;}}cout<<"GOOD SET ";}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
No Prefix Set
You are viewing a single comment's thread. Return to all comments →
C++ Solution. Passed all the tests