Skip to content
DeepForgeby svx
All problems
HardData Structuresds-113

Trie Wildcard Search

Problem

Simulate a trie whose search supports the wildcard character "." matching any single letter.

operations contains "insert" or "search"; words provides the argument. insert records None and search records whether a stored word matches, where each "." in the pattern may stand for any character. Matching uses recursion that branches on wildcards.

Return the list of recorded results.

Hint

A dot explores every child; the end marker is not a child character.

Test cases

case 1
in: [["insert","search","search"],["bad","bad",".ad"]]
expected: [null,true,true]
case 2
in: [["insert","insert","search","search"],["mad","dad",".ad","b.."]]
expected: [null,null,true,false]
case 3
in: [["insert","search"],["a","."]]
expected: [null,true]
case 4
in: [["search"],["."]]
expected: [false]
Starter codePython
def wildcard_trie_ops(operations, words):
    # Your code here
    pass

4 test cases · run your code against them in the editor