Applied AI Engineer (LLM) coding learning path Level 3 This level · 15 of 27

Design Add and Search Words Data Structure

Medium Trie DFS

Problem

Implement a dictionary that can add a word and search for a word, where the search pattern may contain '.' to match any letter.

Original: LeetCode 211: Design Add and Search Words Data Structure.

Examples

Example 1

Input`WordDictionary: addWord("bad"), addWord("dad"), addWord("mad"), search("pad"), search("bad"), search(".ad"), search("b..")`
Output`[null, null, null, false, true, true, true]`

Constraints

  • 1 <= word.length <= 25
  • word in addWord consists of lowercase English letters.
  • word in search consist of '.' or lowercase English letters.
  • There will be at most 2 dots in word for search queries.
  • At most 10^4 calls will be made to addWord and search.

Hints

Solution

Tried it yourself? The approach, complexity, and code stay hidden until you choose.

Sources (1)
  1. LeetCode 211: Design Add and Search Words Data Structureleetcode.com
Previous
Next