Parsing, Serialization, And Deserialization
Asked of: Software Engineer
Last updated

What's being tested
These problems test stack-based parsing, robust tokenization, and unambiguous serialization/deserialization design under adversarial inputs. Interviewers are probing linear-time parsing patterns, correct handling of nesting/precedence, and safe encoding choices that preserve arbitrary bytes/characters.
Patterns & templates
-
Stack-based bracket matching — push opening, on closing
popand compare; linearO(n)time,O(n)worst-case space, handle multiple bracket types. -
Shunting-yard / operator-precedence — convert infix to RPN for safe evaluation; implement precedence and left/right associativity explicitly.
-
Recursive descent parser — small, readable parser for expressions with unary
+/-, parentheses; good when grammar is simple and deterministic. -
Length-prefix (size + data) serialization — encode each string as
<len>#<data>or binary 4-byte length, avoids escape complexities and preserves empties. -
Escape-based encoding — use only when stable delimiter sets; require robust escape rules and validate during decode to avoid ambiguity.
-
DFS/BFS crawler with
visitedset — domain-filtered traversal, cycle avoidance viavisited, respect polite limits (depth, rate). -
Tokenization first, parse second — separate lexical analysis from parsing to simplify unary vs binary operator resolution and variable substitution.
Common pitfalls
Pitfall: Treating unary
-as binary; always detect operand absence left of operator and handle as unary with correct precedence.
Pitfall: Using simple delimiter
splitfor serialization; strings may contain delimiter or be empty—prefer length-prefix.
Pitfall: Forgetting cycle detection in web crawl — omit a
visitedset and the crawler can loop indefinitely.
Practice these
The practice cards below cover the canonical variants — solve all of them and time yourself.
Practice questions
- Serialize a List of Arbitrary Strings into One String and Back, Then Compare SchemesSnowflake · Software Engineer · Onsite · medium
- Implement Document Predicate APIsSnowflake · Software Engineer · Technical Screen · medium
- Implement crawler and bracket validatorSnowflake · Software Engineer · Onsite · medium
- Solve build ordering and expression evaluationSnowflake · Software Engineer · Technical Screen · medium
- Serialize and deserialize a dictionary trieSnowflake · Software Engineer · Onsite · medium
- Check balanced parentheses with multiple bracket typesSnowflake · Software Engineer · Onsite · medium
- Evaluate arithmetic expression with variablesSnowflake · Software Engineer · Technical Screen · medium
Related concepts
- String Processing, Parsing, And Output FormattingCoding & Algorithms
- String Parsing, Palindromes, And NormalizationCoding & Algorithms
- String Parsing, Tokenization, And ValidationCoding & Algorithms
- Binary Serialization And Persistent Key-Value StoresCoding & Algorithms
- Serialization, Binary Encoding, And Persistent KV StoresCoding & Algorithms
- String Scanning, Parsing, And FormattingSoftware Engineering Fundamentals