FastPrepRender a Source-Backed Markdown Subset
Problems/Render a Source-Backed Markdown Subset

Render a Source-Backed Markdown Subset

Samsara logoSamsara● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Two reports describe the same recurring Samsara Markdown-to-HTML parser. The older report gives paragraphs, line breaks, blockquotes, and strikethrough. The newer report also names strong tags. Our version covers the combined set of rules and is about 95% the same as the reported question.

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) → String

Examples

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.
  • text contains ordinary characters and newline characters.

More Samsara interview questions

  • Parse Command-Line TokensONSITE INTERVIEW · Seen Jul 2024

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
All Samsara interview questionsSee Samsara hiring insights
Saved
class Solution {
    public String renderLightweightMarkup(String text) {
        // Write your code here.
    }
}

Not a valid String

Checking account…