DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
medium
Trie

Design Add and Search Words

**Problem Statement:** Given the required input arguments, write an efficient algorithm to solve the **Design Add and Search Words** problem. Implement the required logic as specified by standard definitions for this classic algorithmic challenge. **Hint / Expected Approach:** Trie with DFS for wildcard '.' **Edge Cases to Consider:** - (1) Search with all dots - (2) Empty search string - (3) Word not in trie but prefix is

Examples

Example 1
Input: addWord("bad"); addWord("dad"); addWord("mad"); search("pad"); search("bad"); search(".ad"); search("b..")
Output: false; true; true; true
Explanation: Classic
Example 2
Input: addWord("a"); search(".")
Output: true
Explanation: Dot matches
Example 3
Input: search("a")
Output: false
Explanation: Empty trie

Constraints

  • ▪Input arguments are within valid ranges
  • ▪Optimize for execution speed
  • ▪Handle null/empty inputs gracefully

Watch Out For Edge Cases

  • ▪Search with all dots
  • ▪Empty search string
  • ▪Word not in trie but prefix is
Frequently Asked At
AmazonGoogleMicrosoftMetaAdobe