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.
- No Prefix Set
- Discussions
No Prefix Set
No Prefix Set
Sort by
recency
|
226 Discussions
|
Please Login in order to post a comment
I have an issue with the problem description, as it is tailored to a specific solution. Not only having to print "the string being checked" instead of specifically the prefix or string that contains the prefix is inconsistent, but correct answers are marked as wrong. For example, in the test case they show:
4 aab aac aacghgh aabghgh
there are actually FOUR correct answers: aab is a prefix of aabghgh and aac is a prefix of aacghgh. Since we can print any string of the prefix-prefixed pair, we could technically print any of these and be correct. HOWEVER, only BAD SET aacghgh is correct, because they assume we will be solving the problem in a specific way.
Good problem but bad solution criteria, in my opinion.
I'm in doubt here. Following the problem description and samples explanations, actual test case 1 should print BAD SET with the third string "edchgb", but the test case expect an output of "d" which is evaluated later. Also, "d" is the prefix, not the string that contains it. Can someone explain me this?
my Python 3 attempt by incrementally inserting words into a trie (thanks to inspiration from many of you guys) (must be some other "cleaner" way to do the create dict if not exists step, but I prefer readability in my own terms XD):
edit: simplified and updated thanks to @dgzwiro !
I'd love to hear some opinions on my solution.
def noPrefix(words): word_dict = dict()
Tried using
.sort()
such that the solution boils down to comparing neighbouring words. Unfortunately this violates the "tested first" condition due to the reordering of words: