Longest Common Prefix

Problem Statement

Find the longest common prefix among a list of strings using a trie.

Example: ["flower","flow","flight"] → "fl"

Approach: Trie Path Traversal

Explanation: Insert all words into trie. Traverse from root until a node has multiple children or end-of-word.

Time Complexity: O(N*L), N = #words, L = avg length

Space Complexity: O(N*L)

insert all words in trie
prefix = ""
node = root
while node has exactly one child and not end-of-word:
    node = child
    prefix += child_char
return prefix