In a technical interview, you’ve been asked to design a class WordFilter that supports one function, WordFilter.f(String prefix, String suffix). It will return the word with given prefix and suffix. If no word exists, return -1.
WordFilter.(["apple"]) WordFilter.(["app"]) WordFilter.f("a", "e") // returns 0 WordFilter.f("b", "") // returns -1
Hints
While most structures are designed to manage Generic data, other models are more efficient when managing textual data. As a result, these specialized solutions are often at the core of search engine requests, dictionaries and many types of games.