Sort by

recency

|

171 Discussions

|

  • + 0 comments

    Why submission TestCase 1 is print "d" ? but not "dcjaichjejgheiaie"?

    "dcjaichjejgheiaie" should test before "d".

  • + 0 comments

    Java 8 solution, passed all the tests

        public static void noPrefix(List<String> words) {
            final Set<String> strings = new HashSet<>();
            final Set<String> subSets = new HashSet<>();
            final int size = words.size();
            for (int i=0; i< size; i++){
                final String checkedWord = words.get(i);
                //Check if the current word is subset of previous words
                if(subSets.contains(checkedWord)){
                    System.out.println("BAD SET");
                    System.out.print(checkedWord);
                    return;
                }
                
                for(int j=1; j<=checkedWord.length(); j++){
                    final String subSet = checkedWord.substring(0, j);
                    //Check if any previous word is a subset of the current word
                    if(strings.contains(subSet)){
                        System.out.println("BAD SET");
                        System.out.print(checkedWord);
                        return;
                    }
                    subSets.add(subSet);
                }
                strings.add(checkedWord);
            }
            
            System.out.println("GOOD SET");
    
        }
    
  • + 0 comments

    c++ solution

    bool isless_m( string str1,  string str2) {
        int N = min(str1.size(), str2.size());
        for (int i = 0; i < N; ++i) {
            if (str1[i] < str2[i]) {
                return true;
            }
            else if (str1[i] > str2[i]) {
                return false;
            }
        }
        return false;
    }
    
    void noPrefix(vector<string> words) {
           
        if (words.size() == 1) {
            cout << "GOOD SET\n";
            return;
        }    
    
        set<string,decltype(&isless_m)> mp(&isless_m);
    
        for (int i = 0; i < words.size(); ++i) {
            auto it=mp.insert(words[i]);
            if (!it.second) {
                 cout << "BAD SET\n";            
                cout << words[i]<<"\n";
                return;
            }
        }
        cout << "GOOD SET\n";
       
    }
    
  • + 0 comments

    Dumb question dumb answer. Passes all tests though.

    def noPrefix(words):
        # Write your code here
        content = {}
        subs = {}
        for word in words:
            content[word] = content.get(word, 0) + 1
            for i in range(len(word)-1):
                subs[word[:i+1]] = 1
            if word in subs:
                print('BAD SET')
                print(word)
                return
            for i in range(len(word)):
                if word[:i+1] in content:
                    if i == len(word)-1:
                        if content[word] > 1:
                            print('BAD SET')
                            print(word)
                            return
                    else:
                        print('BAD SET')
                        print(word)
                        return
        print('GOOD SET')
    
  • + 0 comments

    Test case 1 in submission seems expecting an incorrect answer.