Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Design Add and Search Words Data Structure

Medium

Topics
TrieDesignDFSString

Design a data structure with addWord(word) and search(word). In search, a . can match any single letter. search returns whether any added word matches.

Example 1

Input:  operations = ["WordDictionary","addWord","addWord","addWord","search","search","search","search"], values = [[],["bad"],["dad"],["mad"],["pad"],["bad"],[".ad"],["b.."]]
Output: [null,null,null,null,false,true,true,true]

Constraints

  • 1 <= word.length <= 25
  • Added words are lowercase letters; search words may contain ".".
  • At most 10^4 calls.
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access