Longest Prefix

Solve a medium-level problem to find the longest word with all prefixes present in a list using tries.

Problem statement

Given a list of string words, find the longest string in words such that every prefix of that string is also present in words. If there is more than one string with the same length, return any valid string; if none exists, return -1 as string.

Example 1

Sample input

Get hands-on with 1200+ tech skills courses.