Skip to content

Bug Report for design-word-search-data-structure #5498

@TannerLow

Description

@TannerLow

Bug Report for https://neetcode.io/problems/design-word-search-data-structure

Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.

Test case 12 doesn't follow the problem constraint of "There will be at most 2 dots in word for search queries."

["WordDictionary","addWord","addWord","search","search","search","search"]
[[],["development"],["deployment"],["d.ve..p.ent"],["..ment"],["d..ent"],["..ment"]]

Here is code to trigger failure on this test case:

class WordDictionary {
public:
    unordered_set<string> words;

    WordDictionary() {
        
    }
    
    void addWord(string word) {
        words.insert(word);
        
        for(int i = 0; i < word.size(); i++) {
            char a = word[i];
            word[i] = '.';
            words.insert(word);
            for(int j = i+1; j < word.size(); j++) {
                char b = word[j];
                word[j] = '.';
                words.insert(word);
                word[j] = b;
            }
            word[i] = a;
        }
    }
    
    bool search(string word) {
        return words.find(word) != words.end();
    }
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions