No Prefix Set

Sort by

recency

|

222 Discussions

|

  • + 0 comments

    Tried using .sort() which could have been an effective O(n) solution as you only have to compare neighbouring words. Unfortunately this violates the "tested first" condition due to the reordering of words:

    def noPrefix_fail(words: list) -> None:
        words.sort()    # sort leixcographically
        for w1, w2 in zip(words, words[1:]): # sliding window of word pairs
            if w2.startswith(w1):
                print("BAD SET")
                print(w1)   # incorrect due to .sort()
                return
        print("GOOD SET")
    
  • + 0 comments

    The test cases are bad. They are bad because author is making an assumption on which data structure the developer is going to use. If you try to brute force the problem then you might be left scratching your head as to why it is not working. But if you use a Trie then the test cases make sense.

    For example on test case 1:

    If you use brute force you will check first if aab is a prefix of any other words in the list. This means that you will test aabghgh first and that is what you will print.

    If you use a Trie tree, then you will first start building the tree with aab, next you will modify the tree with aac, then you will begin to modify the tree with aacghgh. At this point you will find that aacghgh does have a prefix, and it will get printed, thus passing the test case.

    Test cases should be written in a way that are agnostic of the algorithm that the developer uses to solve it. There are always so many ways to solve the same problem. If the test cases are not agnostic then it should be clear to the developer what algorithm should be used up front.

  • + 0 comments

    That's the end of the 1 week prep kit, it was something ig, what do I get

  • + 0 comments

    Horrible question descrtiption...

  • + 1 comment

    For some test cases it seems to want the first word that is a prefix (even if it comes after a word that contains a prefix), and for others it wants the first word that contains a prefix. Anyone else experience this?