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.
TrieNoderoot=newTrieNode();for(Stringword:words){TrieNodecurr=root;booleannodeAdded=false;for(intj=0;j<word.length();j++){if(curr.isWord){//Found prefix in the treeSystem.out.println("BAD SET");System.out.println(word);return;}if(!curr.children.containsKey(word.charAt(j))){curr.children.put(word.charAt(j),newTrieNode());nodeAdded=true;}curr=curr.children.get(word.charAt(j));}curr.isWord=true;if(!nodeAdded){//No new node added means the word is a prefixSystem.out.println("BAD SET");System.out.println(word);return;}}System.out.println("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 →
Java