Prefix and Suffix Search

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

Problem statement

Given a list of words and two strings pre and suff, return the index of the word that has pre as its prefix and suff as its suffix. If there are multiple valid answers, then return the bigger index. Return -1 if no valid word exists in the list.

Please note that the words list is zero-indexed.

Example 1

Sample input

Get hands-on with 1400+ tech skills courses.