No Prefix Set

  • + 1 comment

    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:

    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")