Search⌘ K
AI Features

DIY: Design Add and Search Words Data Structure

Implement a WordDictionary class to add words, search with support for wildcard characters, and retrieve all stored words. This lesson helps you understand how to design and code a dynamic word search data structure useful for coding interview problems.

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:

  • new(): This function will initialize the object.
  • add_word(word): This function will
...