Optimized Prefix and Suffix Search

Solve a hard-level problem of finding the words that start with a given prefix and end with a given suffix optimally using tries.

Problem statement

Given a list of words and two strings pre and suff, return the index of the word with the string pre as its prefix and the string suff as its suffix. If there are multiple valid answers, then return the bigger index. Solve this problem using a single trie.

Example 1

Sample input

Get hands-on with 1200+ tech skills courses.