Implement Markdown-to-HTML parser
Company: Samsara
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: This question evaluates parsing and string-processing skills, including tokenization, stateful scanning, inline versus block-level markup handling, edge-case management (e.g., unmatched delimiters, trailing spaces, empty paragraphs) and reasoning about time and space complexity.
Constraints
- 0 <= len(text) <= 200000
- The parser only needs to support paragraphs, soft line breaks, blockquotes, and strikethrough as described.
- A blockquote marker is recognized only when a line starts with the exact prefix `> `.
- Strikethrough markers `~~` are paired left to right within the same block only; unmatched final `~~` is treated as literal text.
Examples
Input: ("This is a paragraph with a\nsoft line break.\n\n> Some quoted text\n> continues here\n\nThis has a ~~strikethrough~~ word.",)
Expected Output: "<p>This is a paragraph with a<br/>soft line break.</p><blockquote>Some quoted text<br/>continues here</blockquote><p>This has a <del>strikethrough</del> word.</p>"
Explanation: Two paragraph lines become one `<p>` with `<br/>`, the quoted lines become one `<blockquote>`, and the paired `~~` becomes `<del>`.
Input: ("5 < 6 & 7 > 3\n>not a quote\n~~open only",)
Expected Output: "<p>5 < 6 & 7 > 3<br/>>not a quote<br/>~~open only</p>"
Explanation: The second line is not a blockquote because it starts with `>` but not `> `. The final unmatched `~~` is kept literally.
Hints
- Scan the input line by line. Blank lines end the current block, and switching between quoted and non-quoted lines also starts a new block.
- Handle inline parsing one block at a time. A simple state machine for whether you are currently inside `~~...~~` avoids quadratic rescanning.