No Prefix Set

Sort by

recency

|

229 Discussions

|

  • + 0 comments

    If you're wondering why your test case doesn't work, it's because the test cases are wrong, not your solution.

    They expect you to use a trie but this is not in the instructions, yet the order in which the first bad string appears depends entirely on your solution. The deteciton of any bad string should have been sufficient to solve this problem.

  • + 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
    
  • + 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");
        }
    
  • + 0 comments

    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.

  • + 2 comments

    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?