Search⌘ K
AI Features

DIY: Design Add and Search Words Data Structure

Explore how to design a WordDictionary data structure in Scala that supports adding new words, searching words with wildcard characters, and retrieving all stored words. This lesson helps you develop skills applicable to real coding interviews by implementing key functions and handling search complexities.

Problem statement

Design a data structure that supports the following functions:

  • Adding new words.
  • Finding if a string matches any previously added string.
  • Returning all the words that are present in the data structure.

Let’s call this data structure the WordDictionary class. Here is how it should be implemented:

  • WordDictionary(): This function will initialize the object.
  • void addWord(word): This
...