All topics
131

Turning keystrokes into suggestions

Tier 1Locked

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 included

On 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.

We use necessary cookies to run the site (sign-in and language). If you accept, we also load Google Analytics to see which pages are used, and Google reCAPTCHA to keep spam off the contact and bug-report forms. Privacy policy