Amazon: Longest word built one letter at a time from a word list
Problem. You are given a list of words. Starting from the shortest words, you may grow a word by adding a single character at each step, but every intermediate word you pass through must itself be in the list. Return the longest word that can be reached this way.
How it was asked. It was the second question of the first coding round for SDE2, after a standard lowest-common-ancestor warm-up. No input limits were given in the post.
Approach the candidate used. They loaded every word into a trie and walked it, only moving down into a child when that child marks the end of a complete word. Any branch where a prefix is not itself a word gets cut off, so the deepest node reached through valid words is the answer.
What mattered. The candidate reported strong feedback for this round. The second coding round in the same loop asked a recipes-and-ingredients dependency problem, where a recipe can be an ingredient of another recipe, and they modeled that as a graph with a topological sort.
Comments 0
No comments yet. Ask the author something, or add what happened in your own round.