Skip to main content
Medium Trie Low frequency

Longest Word in Dictionary

Open on LeetCode

Approach Summary

Insert all words into a Trie, marking word ends. BFS/DFS through Trie: only traverse edges where a word ends. Track the longest path.

How to Recognize This Pattern

  • Word is valid only if every prefix is also a word
  • Trie traversal: only follow complete-word nodes

Complexity Analysis

Time Complexity

O(∑ word lengths)

Space Complexity

O(∑ word lengths)

Tags

Array Hash Table String Trie Sorting

This site is free. If these guides are helping your prep, consider buying me a coffee. ☕

Support →
Buy me a coffee