Dsa
Trie
Hard
Radix Trie Node Compression
In a standard trie, every character in a word creates a new node. A 'Radix Trie' compresses paths: a sequence of nodes is merged if nodes have only one child and are not terminals (word endings). Given a set of words, calculate the number of nodes that would exist in a compressed Radix Trie. The root node always exists. A node is preserved if: 1. It is the root. 2. It is a word's terminal. 3. It has more than one child.
Input Format: A sequence of space-separated strings.
Output Format: An integer representing the total number of preserved nodes.
Example:
Input: abc abd
Output: 4
Explanation: Nodes: Root, node after 'ab' (branching), leaf 'c', leaf 'd'.
Key concepts
radix-triestructural-analysis
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now