Solved LeetCode 720: Longest Word in Dictionary using Trie and DFS

📌 Day 51/100 – Longest Word in Dictionary (LeetCode 720) 🔹 Problem: Given an array of words, find the longest word that can be built one character at a time by other words in the array. If multiple results exist, return the lexicographically smallest one. 🔹 Approach: Built a Trie structure to store all words. Used DFS traversal to explore all valid prefixes (where every prefix forms a valid word). Updated the answer when a longer or lexicographically smaller valid word was found. 🔹 Key Learning: Deepened understanding of Trie traversal with DFS. Practiced combining lexicographical comparison with prefix validation. Reinforced prefix-based word-building logic efficiently. 🔹 Complexity: Time: O(N × L) — N = number of words, L = average word length Space: O(26 × N × L) — for Trie storage #Day51Of100 #LeetCode720 #100DaysOfCode #Java #DSA #Trie #DFS #ProblemSolving #CodingChallenge #Strings #DataStructures #CodingJourney #KeepLearning

  • text

To view or add a comment, sign in

Explore content categories