Skip to content
We areTOP 1%

Longest Word in Dictionary

MediumLeetCodeTrie
Solve on LeetCode(opens in a new tab)
Track your progress
First attempt
Re-solve after a few days
Final pass before interviews
Approach hintTry it first, then reveal

Insert every word into a trie, then explore only through nodes that end a word, since each prefix must itself be in the list. Visiting children in alphabetical order makes ties resolve to the smallest word.

More in Trie

Trie questions
#ProblemPlatformDifficultyOpen1st1st Visit2nd2nd VisitRevRevise
1Implement Trie (Prefix Tree)LeetCodeMedium Solve Implement Trie (Prefix Tree) on LeetCode (opens in a new tab)
2Longest Word in DictionaryLeetCodeMedium Solve Longest Word in Dictionary on LeetCode (opens in a new tab)
3Design Add and Search Words Data StructureLeetCodeMedium Solve Design Add and Search Words Data Structure on LeetCode (opens in a new tab)
4Maximum XOR of Two Numbers in an ArrayLeetCodeMedium Solve Maximum XOR of Two Numbers in an Array on LeetCode (opens in a new tab)
5Polycarp's phone bookCodeforcesMedium 1600Solve Polycarp's phone book on Codeforces (opens in a new tab)
6Good SubstringsCodeforcesHard 1800Solve Good Substrings on Codeforces (opens in a new tab)
7Vasiliy's MultisetCodeforcesHard 1800Solve Vasiliy's Multiset on Codeforces (opens in a new tab)
8Perfect SecurityCodeforcesHard 1800Solve Perfect Security on Codeforces (opens in a new tab)
9Maximum XOR With an Element From ArrayLeetCodeHard Solve Maximum XOR With an Element From Array on LeetCode (opens in a new tab)
10Word Search IILeetCodeHard Solve Word Search II on LeetCode (opens in a new tab)

Sign in to track your progress

Your checkboxes, streak and activity heatmap are saved to your account and sync across devices. It is free.
Sign in with email

New here? Create an account