Prefix and Suffix Search

Design a special dictionary that searches words by a prefix and a suffix.

Implement the WordFilter class:

  • WordFilter(words) initializes the object with the words in the dictionary.
  • f(prefix, suffix) returns the index of the word in the dictionary that has prefix prefix and suffix suffix. If there is more than one valid index, return the largest of them. If there is no such word, return -1.
Examples
Input: []
Output: 0
Hints

Prefix and Suffix Search

Design a special dictionary that searches words by a prefix and a suffix.