No Prefix Set

  • + 0 comments

    From reading this discussion it seems this is seeing if we used a trie. Even so, this doesn't timeout and I think the logic seems to check out. Given their criteria that words are tested in order, and the prefix 'aab' is lower indexed compared to 'aac'. Guess im skipping this one.

    def noPrefix(words):
        if len(words) == 1:
            return
        
        seen = set()
    
        for i in range(len(words)):
            target = words[i]
            seen.add(target)
            for j in range(i, len(words)):
                if i == j:
                    continue
    
                if words[j] in seen:
                    print("BAD SET")
                    print(words[j])
                    return
                    
                if len(words[j]) > len(target) and words[j][0:len(target)] in seen:
                    print("BAD SET")
                    print(words[j])
                    return