Design a trie that supports inserting words, searching exact words, and checking whether a prefix exists. Pattern focus: Trie Node Structure. Build a clean node model and keep the operations consistent across empty, duplicate, and prefix-heavy inputs.
operations = trie commands, values = command arguments
boolean results for each search or startsWith command in order
Example 1:
Input:
operations = ["insert","search","search","startsWith","insert","search"] values = ["apple","apple","app","app","app","app"]
Output:
[true,false,true,true]
Explanation:
Insert one word, verify an exact match, test a missing word, then add the prefix word and confirm it exists.
Example 2:
Input:
operations = [] values = []
Output:
[]
Explanation:
No trie commands produces no query results.
Example 3:
Input:
operations = ["insert","insert","search","startsWith"] values = ["hello","hello","hell","he"]
Output:
[false,true]
Explanation:
Duplicate inserts should not break search or prefix lookup.