Where it runs
1. The problem
You type "app" into a search box. A dropdown opens with "apple", "application", "apply". This happens on every keystroke, over a word list that might hold a million words.
Last step you built a trie (a tree of letters). It answers one question about a prefix: does any word start with it? Yes or no. Autocomplete needs more. It needs the words themselves that start with "app", and it needs them in a fixed order. This step turns the trie from a yes/no check into a source of suggestions.
This step is part of the paid track
The first 33 steps are open to everyone: lesson, exercise and tests. This one opens with full access. Start with a free account and the free steps.
Create a free accountSee what is includedOn LeetCode
Problems that list or score every word under a prefix, such as search suggestions or the sum of values for a prefix. Walk down to the prefix node, and a DFS below it in letter order gives the words already sorted.
The lesson task. After each typed letter, walk to the prefix node and return the first three words of the DFS.
Store each key's value at its end node, and sum(prefix) adds up every value in the subtree below the prefix.
Insert every word, then DFS only through nodes that end a word, and keep the longest word, the smallest one on a tie.
Count on each node how many words pass through it, and a word's score is the sum of the counts along its path.