Serialize a Suggestion Trie to a Compact String and Back

Last updated: November 29, 2026

Quick Overview

Write serialize(trie) producing a compact string and deserialize(s) rebuilding an identical trie, where nodes may be word ends and children are single characters.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Write serialize(trie) producing a compact string and deserialize(s) rebuilding an identical trie, where nodes may be word ends and children are single characters.

A Google technical screen question tied to shipping an on-device autocomplete dictionary, for example in Chrome or Gboard, where the trie is built server-side and loaded on the client. The interviewer checks a preorder encoding with explicit end-of-children markers and an unambiguous format.

What the Interviewer Expects
  • Choose a preorder format with child markers and a close marker
  • Encode the word-end flag per node
  • Make the format unambiguous for every character in the alphabet
  • Deserialize with an index or stack without recursion depth issues
  • Compare size against storing the word list
Key Topics to Cover
trie
serialization
preorder traversal
encoding
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you make the format binary and memory-mappable?
  • How would you add frequencies per word end?
  • When is storing the sorted word list with front coding smaller?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Trie nodes are dicts of char -> child plus an end flag. serialize(root) returns a string; deserialize(s) returns a trie that stores the same set of words. Characters are lowercase letters, so we...

High-Level Design

Do a preorder traversal. For each node emit * if it ends a word, then for each child emit the child's character followed by the child's serialization, and finally emit ) to close the node. Because...


Submit Your Answer
Markdown supported