The engine should know how many distinct words it holds, and that count must not double-count a word inserted twice. Today you make Len exact by only counting a word the first time its end marker flips on.
Track the number of distinct stored words, counting each word exactly once.
The word count lives on the Trie as size, but the trick is updating it
correctly. Marking end unconditionally would let a repeated Insert("car")
inflate the count even though no new word arrived. So guard it: only when the
final node’s end was false before this insert has a genuinely new word been
added, and only then do you flip end and increment size.
Inserting car, cart, care adds three distinct words, so Len() is 3.
Inserting car a fourth time finds an already-ended node and changes nothing;
inserting cab ends a new node and takes the count to 4. This exact-count
guarantee is what lets later lessons trust that “return everything” really means
every stored word, once each.
func (t *Trie) Insert(word string) {cur := t.rootfor _, r := range word {// ... walk/create children as before ...}if !cur.end { // only a NEWLY ended word bumps the countcur.end = truet.size++}}