Design a data structure that efficiently stores words and supports searching for words with wildcard characters. This problem tests your understanding of tries and recursive searching, crucial for applications like autocomplete and spellcheck.
Implement a custom data structure that enables the insertion of words and the searching of words. The search functionality must support the use of a special wildcard character, denoted by '#', which can match any single lowercase English letter. The data structure should support two primary operations: adding a word and searching for a word (potentially containing wildcards).
A brute-force approach would involve storing all inserted words in a list and, for each search query, iterating through the list and comparing each stored word with the query. For wildcard matches, you'd need to check every possible character substitution. This is like manually searching through a phone book, comparing each name one by one. This is inefficient.
Work through this problem with AI coaching and get real-time feedback
Practice This Problem