Dashboard
LC #211

Design Add and Search Words Data Structure

Pattern · ?AmazonGoogleMeta

Problem

Design a data structure that supports adding words and searching with '.' as wildcard.

Constraints

  • 1 ≤ word.length ≤ 25
  • word in addWord consists of lowercase English letters
  • word in search consist of '.' or lowercase English letters
  • At most 10⁴ calls total

Example

Input
addWord("bad"), addWord("dad"), search("pad"), search("bad"), search(".ad"), search("b..")
Output
false, true, true, true
Why
'.' matches any letter. ".ad" matches "bad" or "dad". "b.." matches "bad"

Spot the pattern

Which pattern cracks it?

Hints

One at a time
Solve on LeetCode ↗