Prefix and Suffix Search
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Implement WordFilter(words), which indexes a list of words so that combined prefix-and-suffix lookups are fast.
f(pref, suff) returns the **largest index** i such that words[i] starts with pref and ends with suff, or -1 if no word does. The prefix and the suffix may overlap inside the word, and each may equal the entire word. The list may contain duplicate words; the later index wins.
Words are short (at most 7 letters) but there can be many words and many queries, so precomputation is worthwhile.
Examples
Constraints
- 1 <= words.length <= 10^4
- 1 <= words[i].length <= 7
- 1 <= pref.length, suff.length <= 7
- All strings consist of lowercase English letters
- At most 10^4 calls to `f`
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.