Compressed Radix Tree for Memory-Lean URL Path Lookup
Last updated: November 29, 2026
Quick Overview
Implement insert(key) and contains(key) / starts_with(prefix) on a radix tree, where edges carry whole substrings and nodes with a single child are merged to save memory.
0
0
0 solved
Implement insert(key) and contains(key) / starts_with(prefix) on a radix tree, where edges carry whole substrings and nodes with a single child are merged to save memory.
A Google onsite coding question aimed at engineers working on serving infrastructure, where millions of URL paths share long prefixes. The interviewer checks correct edge splitting on insert and careful handling of partial edge matches in prefix queries.
What the Interviewer Expects
- Store edge labels as strings rather than single characters
- Find the longest common prefix between the key and an edge label
- Split an edge when the key diverges mid-label
- Handle prefix queries that end inside an edge label
- Explain the memory saving over a character trie
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you implement delete with re-merging of single-child nodes?
- How would you index children for fast lookup by first character?
- How does this relate to the Patricia trees used in routing tables?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
insert(key) adds a string. contains(key) checks exact membership. starts_with(p) returns True if any stored key begins with p. Children are indexed by the first character of their edge label....
High-Level Design
Each node maps a first character to an edge (label, child). To insert, look up the edge starting with the key's first character. If none, add an edge with the entire remaining key. Otherwise compute...