Convert Email Text to Structured Markup
Updated
Problem statement
Convert a plain-text email message into a compact markup string made from <Paragraph>, <Quote>, and <Break /> components.
- One or more empty lines end the current paragraph or quote block.
- A non-empty line with no leading
>belongs to a paragraph. Consecutive paragraph lines are joined with<Break />. - A line beginning with one or more
>characters belongs to a quote. The number of leading markers is its quote depth, and those markers are removed from the rendered text. - Quote depth may increase or decrease between consecutive quote lines. Increasing the depth opens nested
<Quote>components. Decreasing it closes components until the requested depth remains. - Consecutive text lines at the same quote depth are joined with
<Break />.
Return all rendered components concatenated without extra whitespace.
Function
renderEmailMarkup(message: String) → StringExamples
Example 1
message = "Please tag @Bob Jones for approval!\n\nHere's the max amount we were allotted:\n\n>Max spend: $5000\n>Max spend per user: $12\n>Target spend: $3000\n\nDo you think it will be ok?\nOtherwise let's consider a new vendor."return = "<Paragraph>Please tag @Bob Jones for approval!</Paragraph><Paragraph>Here's the max amount we were allotted:</Paragraph><Quote>Max spend: $5000<Break />Max spend per user: $12<Break />Target spend: $3000</Quote><Paragraph>Do you think it will be ok?<Break />Otherwise let's consider a new vendor.</Paragraph>"Blank lines split the two introductory paragraphs, the three > lines form one quote, and the final single newline becomes a break inside one paragraph.
Example 2
message = "Top\n\n>One\n>>Two\n>Three\n\nEnd"return = "<Paragraph>Top</Paragraph><Quote>One<Quote>Two</Quote><Break />Three</Quote><Paragraph>End</Paragraph>"The second quote line opens a nested quote. Returning to depth one closes that nested component before adding a break and the next outer-quote line.
Example 3
message = "alpha\nbeta"return = "<Paragraph>alpha<Break />beta</Paragraph>"Without a blank separator or quote marker, both lines belong to one paragraph.
Constraints
0 <= message.length <= 100000.- Line endings use
\n. - Text contains printable ASCII characters. Outside leading quote markers, it does not contain
<,>, or&. - A non-empty quote line contains at least one text character after its leading markers.
More Zip Phone Screen questions
- Maximum Survival Time in a Graph PursuitPHONE SCREEN · Seen Sep 2026
- Find All Zip Rummy MeldsPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2026
- Shortest Path Around Moving ParadesPHONE SCREEN · Seen Mar 2026
- Furthest Building with Sandbags and RopesPHONE SCREEN · Seen Feb 2026
- Phrase Covering the Most WordsPHONE SCREEN · Seen Feb 2026
- Translate Values in a Nested MapPHONE SCREEN · Seen Feb 2026
- Maximum Nonadjacent Sum in a General TreePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2025
- Shortest Distance in a GraphPHONE SCREEN · Seen Nov 2025
- Open the Lock and Return a Shortest PathPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2025
- Winning Draws for a Mahjong HandPHONE SCREEN · Seen Sep 2025
Similar questions at other companies
- Most Frequent Call Path From Function Trace LogsRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
- Single-Pass S-Expression ParserBaseten · ONSITE INTERVIEWBaseten interview questions
- Remove Parentheses from a Plus-Minus ExpressionOracle · PHONE SCREENOracle interview questions
- Decode StringCompass International Holdings · PHONE SCREENCompass International Holdings interview questions
- Flatten a Mixed JSON ListNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions
- Molecular Weight of a Grouped FormulaAgoda · ONSITE INTERVIEWAgoda interview questions
- Calculate a Token-List ExpressionCollege Vine · ONSITE INTERVIEW
- Rich Text Parser Part 3 (Depth Tokens)Figma · PHONE SCREEN · ONSITE INTERVIEWFigma interview questions
- Parse Nested HTML into a TreeApple · ONSITE INTERVIEWApple interview questions
- Calculator with ParenthesesGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions