No Prefix Set

  • + 0 comments

    after looking at the discussions i get that the question is looking for a Trie implementation. but i just can't see how the following solution doesn't work for all the test cases, because as far as i can see it satisfies every requirement in the question:

        public static void noPrefix(List<string> words)
        {
            for(int word = 0; word < words.Count; word++){
                for(int prefix = 0; prefix < words.Count; prefix ++){
                    if(word == prefix) continue;
                    if(words[word].StartsWith(words[prefix])){
                        Console.WriteLine($"BAD SET");
                        Console.WriteLine(words[word]);
                        return;
                    }
                }
            }
            Console.WriteLine("GOOD SET");
        }