Loading problem…
Implement WordFilter(words), keeping the original zero-based word indices. Its method f(pref, suff) returns the largest index of a word that starts with pref and ends with suff. Return -1 if no word matches both conditions.
Prefixes and suffixes may overlap, and repeated words keep their separate indices. Queries are case-sensitive; all input characters are lowercase English letters. The dictionary does not change after construction.
Tests provide named operations and values arrays, with the constructor first. Its output is represented by null.
Example 1:
Example 2:
Example 3: