-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Open
Description
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();
}
};
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels