FastPrepParse Nested Message Types
Problems/Parse Nested Message Types

Parse Nested Message Types

Applied Intuition logoApplied Intuition● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report asks for a message-type parser and extends it to nested types. The bounded grammar and canonical output make that recursive transformation executable.

Special thanks: 🌷 A special thank you to a lovely, amazing fren for sharing that a similar version of this question appeared again on November 5, 2026! ( ˘͈ ᵕ ˘͈♡) 🩵

Parse a valid message-type expression and return its canonical representation.

A type is an identifier made of letters or digits, optionally followed by angle brackets containing one or more comma-separated child types. ASCII whitespace may appear anywhere outside an identifier. A leaf remains its identifier; a parameterized type is returned as Name(child1,child2,...), recursively preserving child order.

Function

canonicalizeMessageType(expression: String) → String

Examples

Example 1

expression = "Map<String,List<Int>>"return = "Map(String,List(Int))"

The nested angle-bracket grammar becomes a canonical parenthesized tree.

Example 2

expression = " Envelope < Message < String > , Metadata > "return = "Envelope(Message(String),Metadata)"

Whitespace is ignored while child order is preserved.

Constraints

  • 1 <= expression.length <= 10^5
  • The expression is valid under the stated grammar.
  • Nesting depth is at most 500.

More Applied Intuition problems

  • Hash Map with Separate ChainingONSITE INTERVIEW · Seen Nov 2026
  • KV Store with Nested TransactionsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Resolve Variable Equations with Dependency ErrorsPHONE SCREEN · Seen Nov 2026
All Applied Intuition interview questionsSee Applied Intuition hiring insights
Saved
class Solution {
    public String canonicalizeMessageType(String expression) {
        // Write your code here.
    }
}
Checking account…