Render a Source-Backed Markdown Subset
Updated
Problem statement
Convert a string containing a bounded Markdown subset to HTML.
- One or more blank lines separate blocks.
- Consecutive ordinary nonblank lines form one
<p>block; a single newline inside it becomes<br>. - Consecutive nonblank lines beginning with
>form one<blockquote>; remove each prefix and join its lines with<br>. - Within one block, paired
**...**becomes<strong>...</strong>and paired~~...~~becomes<del>...</del>. - Inline formatting may span a single newline within its block, but never a blank-line block boundary. Malformed or unmatched delimiters remain literal. Preserve all other punctuation and spaces.
Return the concatenated HTML blocks without extra separators.
Function
renderLightweightMarkup(text: String) → StringExamples
Example 1
text = "Hello, **world**!\nNext line.\n\n> quoted\n> ~~old~~"return = "<p>Hello, <strong>world</strong>!<br>Next line.</p><blockquote>quoted<br><del>old</del></blockquote>"The ordinary lines form one paragraph, the blank line starts a blockquote, and both inline forms are rendered.
Example 2
text = "Keep **open\n\nNew ~~text~~."return = "<p>Keep **open</p><p>New <del>text</del>.</p>"The unmatched strong delimiter cannot cross the paragraph boundary and stays literal.
Constraints
0 <= text.length <= 200000.textcontains ordinary characters and newline characters.
More Samsara interview questions
Similar questions at other companies
- Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- Business Account KYC Verification — Parts 1–5Stripe · PHONE SCREENStripe interview questions
- CSV Row SerializerMercor · PHONE SCREENMercor interview questions
- Host Log ParserVerkada · PHONE SCREENVerkada interview questions
- Length-Prefixed String CodecSnowflake · PHONE SCREENSnowflake interview questions
- Machine Message RouterOpenAI · PHONE SCREENOpenAI interview questions
- HTTP Status Log SummaryApple · PHONE SCREENApple interview questions
- JSON Identity VerificationKikoff · PHONE SCREENKikoff interview questions
- Alert After Repeated Column Threshold BreachesMeta · PHONE SCREENMeta interview questions
- Serialize a Nested Dictionary as JSONGoogle · PHONE SCREENGoogle interview questions