Prefix and Suffix Search
Hard · Trie · about 30 minutes
Asked at Google, Meta, Amazon.
Design a dictionary that finds words by prefix and suffix.
WordFilter(words)stores the words (indexiiswords[i]).f(pref, suff)returns the largest index of a word that starts withprefand ends withsuff, or -1
if there is none.