Parse Nested Message Types
Reported by candidates from Applied Intuition's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks a first attempt on this Applied Intuition OA, reported in September 2026, is treating the string like a regex problem instead of a tiny grammar. You get a nested type like Map<String,List<Int>> and have to return Map(String,List(Int)). Whitespace is scattered everywhere, and the input can run to 10^5 characters with nesting up to 500. It's a string parsing question with a stack or recursion underneath. If you blank on the structure mid-assessment, StealthCoder runs invisibly as a safety net and gives you a working parse. Know the shape first, though.
The problem
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.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is that you don't need a real parse tree. Strip whitespace first, or skip it as you scan. Then walk the characters once. Build identifiers from letters and digits. On '<' emit '(', on '>' emit ')', and keep commas as they are. That's the whole transform, since the input is guaranteed valid and child order never changes. The pitfall is recursion. Depth is capped at 500, which can blow the stack in some languages, so an iterative scan is safer. Another pitfall is string concatenation in a loop. Use a list or builder to stay linear at 10^5. Whitespace is only allowed outside identifiers, so you never need to merge tokens across spaces. If you blank during the live OA, StealthCoder is the hedge that hands you the single-pass version.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Parse Nested Message Types cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Applied Intuition's OA.
Applied Intuition reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Parse Nested Message Types FAQ
How hard is Parse Nested Message Types really?+
Easier than it looks. It's a string problem with a simple grammar. Once you see that angle brackets map directly to parentheses, it's a single pass. The difficulty is in handling whitespace cleanly and not overengineering a parser.
What's the trick to solving it?+
Ignore whitespace, copy identifier characters and commas, turn '<' into '(' and '>' into ')'. Because the input is valid, no tree or validation is needed. A linear scan with a string builder gives the canonical output.
Should I use recursion or a stack?+
Neither is required. A plain character scan works. If you do recurse, depth can reach 500, which is usually fine but risky in some languages. An iterative approach avoids the question entirely and keeps you safe.
What edge cases should I test?+
Test a bare leaf like Int, leading and trailing spaces, spaces around brackets and commas, and deeply nested types. Also try identifiers with digits. Check that sibling order stays unchanged, as in Example 2 with Message before Metadata.
How do I prepare in 48 hours?+
Practice a few string transformation and bracket-parsing problems, like decoding nested strings. Write the single-pass solution by hand twice. Focus on complexity: O(n) time, and a builder instead of repeated concatenation for the 10^5 length.