Trie (prefix tree) · Compiler

Trie (prefix tree)

Insert the given words into a trie that starts with only a root. Each edge represents one letter. Words with a shared prefix use the same path for that prefix. Count all nodes except the root. Marking the end of a word does not add a node.

Input
The first line contains n (0 <= n <= 100). Each of the next n lines contains one word of 1 to 40 lowercase English letters. Words may repeat.
Output
Print the number of non-root nodes after all insertions.

Compiler Explorer runs your code when you run or check it.

Loading your exercise draft…