Problem
Design a data structure that stores words and finds a stored word that matches a pattern.
Write the class WordDictionary with these operations:
WordDictionary() creates an empty data structure. addWord(word) stores the string word. search(word) returns true if a stored word matches word, and false if no stored word matches.
In search, the string word can contain the dot character .. A dot matches any one letter. Each other character matches only the same letter. A stored word must also have the same length as word.
Example 1
- Input:
- ["WordDictionary","addWord","addWord","search","search","search"] [[],["lamp"],["limp"],["l.mp"],["lam"],["...."]]
- Output:
- [null,null,null,true,false,true]
- Explanation:
l.mpmatcheslampandlimp.lamdoes not match, because it is shorter than the stored words.
Example 2
- Input:
- ["WordDictionary","addWord","search","search","search"] [[],["sky"],["s.y"],["sk."],["s.a"]]
- Output:
- [null,null,true,true,false]
- Explanation:
s.adoes not matchsky, because the last letter is different.
Constraints
- 1 <= word.length <= 25
- word in addWord contains only lowercase English letters.
- word in search contains only '.' or lowercase English letters.
- word in search has at most 2 dots.
- At most 10^4 calls to addWord and search
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Design an indexed data structure with insert, replace, and search operations
Coding
- All O`one Data Structure
Coding · Design · Doubly-Linked List · Hash Table
- Classic data structure and algorithm coding problems .
Coding
- Data Structure with O(1) Set All Operation
Coding
Sources · 1 reference
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 2 records
Google
Leetcode 211. Design Add and Search Words Data Structure
Reported Jun 15, 2026 · 1 source report
SENIOR
Source snapshot: Nov 12, 2026
View sourceMicrosoft
Leetcode 211. Design Add and Search Words Data Structure
Reported Nov 8, 2025 · 1 source report
MID_LEVEL
Source snapshot: Nov 12, 2026
View source