Prefix Count / StartsWith
Problem Statement
Given a list of words, implement a method to check if any word starts with a given prefix.
Example: Words: ["apple","app"], Prefix: "ap" → true, Prefix: "bat" → false
Approach: Trie Prefix Search
Explanation: Traverse the trie along prefix characters. If path exists, return true; else false.
Time Complexity: O(P), P = length of prefix
Space Complexity: O(1)
startsWith(prefix):
node = root
for char in prefix:
if char not in node.children:
return False
node = node.children[char]
return True
💡 Think: Step through the prefix; if the path exists to the end of prefix, it's a match.