Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Design Add and Search Words Data Structure

Medium
triedesigndfsstring

Design a data structure that stores words and supports searching with the wildcard . (matches any single letter).

Input: one operation per line —

  • addWord w — add word w
  • search p — print true if any stored word matches pattern p (letters and dots)

Output: one line per operation — addWord prints null; search prints true/false.

Example 1
Input:
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
  • At most 2 dots per search; up to 10^4 operations.
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.