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.
publicstaticvoidnoPrefix(List<String>words){finalSet<String>strings=newHashSet<>();finalSet<String>subSets=newHashSet<>();finalintsize=words.size();for(inti=0;i<size;i++){finalStringcheckedWord=words.get(i);//Check if the current word is subset of previous wordsif(subSets.contains(checkedWord)){System.out.println("BAD SET");System.out.print(checkedWord);return;}for(intj=1;j<=checkedWord.length();j++){finalStringsubSet=checkedWord.substring(0,j);//Check if any previous word is a subset of the current wordif(strings.contains(subSet)){System.out.println("BAD SET");System.out.print(checkedWord);return;}subSets.add(subSet);}strings.add(checkedWord);}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 8 solution, passed all the tests