InterviewLegend

Markdown to HTML Converter

Alex Chen40 min readGuide updated
In this lesson
  • Convert paragraphs, line breaks, blockquotes and strikethrough in one pass over the lines
  • Choose between a split-then-render approach and a single-pass state machine
  • Add inline rules like bold without touching the block code
  • Parse links without regex, leave malformed input alone, and go back from HTML to Markdown

If you interview for a software role at Samsara, there's a good chance you'll be asked to turn Markdown into HTML. Candidates have described it 36 times between October 2019 and April 2026, and it's still the newest problem anyone names. A London intern met it in January 2026, a US candidate in a live session in February, and a London graduate in April. It turns up in the technical phone screen, in the first onsite coding round, in hiring-manager screens and in the single technical interview of intern loops.

The shape has barely moved in six years. A string of plain text goes in, and HTML comes out with paragraphs, line breaks, blockquotes and strikethrough. Variants add bold or ask for at least five rules. The round is built in parts, the interviewer asks you to run your code against tests as you go, and few people finish in 30 to 45 minutes. A 2024 candidate who didn't finish still moved on, so a clean, working first part matters more than reaching the last one.

The Samsara angle
Run the code after every rule. A senior candidate in January 2025 got positive feedback with one exception: they ran the code only after writing all of it. Get paragraphs passing, run, then add the next rule. In April 2026 a graduate's advice was to stay on the main objective and skip extras.

Line scanning or a block state machine

Most people start by splitting the text on a double newline, wrapping each piece in a paragraph tag and replacing the newlines left inside it with a line break. That passes the first test in five minutes. Then the input has a blank line made of three spaces, or a quote that starts halfway through a paragraph, and the splits stop lining up with the blocks. Every new rule means another split and another special case.

The sturdier route walks the lines once and keeps one piece of state, the kind of run you're inside. It's either nothing, a paragraph or a quote. Each line either continues that run or closes it and opens another. That's a small state machine, and the transitions fit in a table:

line inside nothing inside a paragraph inside a quote
blank or spaces stay close the p close the blockquote
starts with "> " open a blockquote close p, open quote add a line
anything else open a p add a line close quote, open p
end of input done close the p close the blockquote

Inline rules like strikethrough run inside a single line, so they get their own tiny scanner that the block loop calls on each line. Keeping the two levels apart is what lets later parts land as small edits. A 2025 write-up of the screen asks you to compare single-pass and multi-pass tokenizing, and this split gives you something concrete to say.

Regex is fine for one inline rule and a poor fit for the blocks. The February 2026 candidate found the live requirements harder than expected with regex. The block rules depend on the line before, which a pattern can't see. Scan lines for blocks, and use a short loop or one pattern per inline rule.

Asked at Samsara

Three problems from current and recent rounds, then one older variant. Each runs against its tests here, so practice the way the round works and run after every rule.

The Markdown to HTML converter

Candidates in 2026 name this problem without listing its rules. Where the rules are spelled out, in a January 2021 phone screen, a November 2020 one and a 2025 write-up, they land on the same four. Expect something like the version below, with wording and test strings that vary by interviewer.

1

Markdown to HTML Converter

MediumSignature problem
Problem
Write markdown_to_html(text) that turns a small Markdown subset into HTML. Lines are separated by \n. A blank line, empty or only spaces, ends a block. Plain lines become a <p>, and a single newline inside one becomes <br />.

A line that starts with exactly > is a quote line. Consecutive quote lines become one <blockquote>, with the prefix removed and the lines joined by <br />. A quote run closes the paragraph above it, and a plain line after it opens a new one. Lines that start with > and no space are plain text.

Inside a line, ~~text~~ becomes <del>text</del>. Pair the markers left to right, and leave a ~~ with no partner as typed. Return the elements joined by \n, one per line, or an empty string when there are none.
Inputtext = "Hello\nworld\n\nNew paragraph"Output"<p>Hello<br />world</p>\n<p>New paragraph</p>"

A single newline stays inside the paragraph as a line break. The blank line starts a second paragraph.

How this uses the pattern

Walk the lines once and remember which run you are in. A blank line, or a switch between quote and plain lines, closes the run and writes its element.

Write it here, or go full screen with the problem, hints and solution beside the editor.

Markdown to HTML Converter

Loading...
Click "Run" to execute your code
The Samsara angle
Samsara builds this in parts, and the interviewer runs your tests between them. A 2021 screen opened with "the beginnings of a markdown processor" covering these four tags. Write the paragraph loop so each later rule is one new branch. A 2020 candidate was told output formatting didn't matter as long as the HTML was valid, so don't spend minutes on indentation.
Take it further
Ask what happens to a quote inside a paragraph. Here it closes the paragraph, which keeps the HTML valid, since a blockquote can't sit inside a <p>. If your interviewer wants the quote nested in its paragraph, agree on that before you code, because it changes when close_run fires. Then expect the next part to add rules, which the next problem covers.

Markdown to HTML with more rules

The base problem has relatives with more rules. In February 2026 a US candidate got a live session where the requirements arrived during the round and called them unique. In May 2024 a UK candidate was asked for at least five rules. A July 2024 phone screen wanted line-break and bold tags, and an October 2019 CoderPad round wanted paragraphs, quotes and bold.

Nobody has posted the full rule list, so the version below is something like it. Paragraphs, line breaks, quotes, strikethrough and bold make five, and the interviewer may add more inline rules mid-round. Practice making a new rule one line of code.

2

Markdown to HTML With More Rules

MediumFrequently asked
Problem
Build a MarkdownConverter. convert(text) follows the block rules of the first problem: blank lines end a block, plain runs become <p>, runs of > lines become <blockquote>, and lines inside one element are joined by <br />. Elements are joined by \n.

Inline rules come from a table. It starts with ~~ for del and ** for strong, and add(marker, tag) adds a rule. Text between a marker and its next copy on the same line is wrapped in that tag, and the inside is converted too, so rules nest.

At each position try the longest marker first, and keep rules of equal length in the order they were added. A marker with no partner later in the line stays as typed.
  1. MarkdownConverter()
  2. convert("**bold ~~gone~~ text**")→ "<p><strong>bold <del>gone</del> text</strong></p>"

The strike sits inside the bold, so its tag nests inside the strong tag.

How this uses the pattern

Keep the inline rules as a list of (marker, tag) pairs sorted longest first. One recursive inline function serves every rule, and the block loop stays the same as in the first problem.

Write it here, or go full screen with the problem, hints and solution beside the editor.

Markdown to HTML With More Rules

Loading...
Click "Run" to execute your code
The Samsara angle
Requirements change mid-round in this variant. With strikethrough hard-coded, adding bold means copying the scanner and editing it. With a rule table, the interviewer's next rule is one call. Recursing on the inside text handles nesting with no extra code. Sorting longest first stops a short marker from stealing the start of a longer one.
Take it further
Ask what happens when markers overlap. Text like **a ~~b** c~~ has no correct nesting. This converter wraps the outer pair and leaves the inner ~~ unmatched inside it. Real Markdown parsers use a delimiter stack to resolve these cases. Describe that if asked, and keep the simple rule in code.

This one rests on a single secondhand listing of a technical screen, from August 2025, and no candidate has described it directly. It's worth an hour anyway, because it drills the scanning that the converter rounds reward. You turn bracketed link text followed by a quoted URL in parentheses into anchor tags, without regex, across a whole string.

The listing names the follow-ups: several links in one string, malformed input left unchanged, the innermost brackets winning, escaped brackets and quotes, complexity and tests. The problem below covers the first three, and the solution works the escapes as a follow-up.

Older problems (2019-2024)

Two candidates got the converter in reverse. A London onsite in November 2019 asked for an HTML-to-Markdown translator, and a Poland coding interview in June 2024 asked for one covering a couple of tags. The candidate called it harder than the second coding round. Neither report lists the tags, so the version below reverses the tags from the first two problems.

HTML to Markdown for a few tags

4

HTML to Markdown for a Few Tags

MediumRarely asked
Problem
Write html_to_markdown(html) for HTML made of <p> and <blockquote> elements, separated by newlines. Each element becomes one Markdown block, and blocks are joined by a blank line.

Inside an element, <br /> becomes a newline (also written <br> or <br/>). Every line of a blockquote starts with > . <del> and its closing tag become ~~, and <strong> and its closing tag become **.

Any other tag is dropped and its text kept. Return an empty string for empty input.
Inputhtml = "<p>Hello<br />world</p>\n<p>Next</p>"Output"Hello\nworld\n\nNext"

The line break becomes a newline, and the two paragraphs are separated by a blank line.

How this uses the pattern

Scan for tags with an index. Text goes onto the current line of the open block. Each tag either opens a block, closes one, starts a new line or adds a marker.

Write it here, or go full screen with the problem, hints and solution beside the editor.

HTML to Markdown for a Few Tags

Loading...
Click "Run" to execute your code
The Samsara angle
Run backwards, the first problem tests the same skill, an index scan that carries a little state. Here it holds the open block's lines and their prefix. A line break inside a blockquote has to start the next line with the quote prefix again, and that's the line most first attempts miss. Ask which tags count before you code, since the 2024 report said only a couple.
Take it further
Check a round trip. For plain input, converting Markdown to HTML and back should give Markdown that converts to the same HTML. A quote between two paragraphs comes back as its own block with blank lines around it, which is still the same HTML. Say why it isn't the identical text, then mention that real HTML needs entity decoding and nested lists, which a full parser handles.

How the round is judged

The interviewer cares about working code that matches the expected output, built and run in steps. In a 2021 screen of 30 minutes, the candidate was told nobody expected the full problem finished, and was still asked again and again to run the code. A 2022 senior candidate finished about three quarters of it in a 30-minute hiring-manager call. The round rewards a working base you can grow.

Run after every rule, and name the edge cases out loud. Start with paragraphs and run. Add line breaks and run. Say what you'll do with an unmatched marker or a quote line with no space before the test finds it. When the interviewer adds a rule, extend the code you have instead of starting again.

Common questions

What coding questions does Samsara ask?

Mostly practical builds that grow in parts. Markdown to HTML is the one candidates name most, from 2019 through April 2026. A command-line argument parser was the other staple of onsite coding through early 2025, and some 2025 and 2026 candidates got a LeetCode-style medium instead. The coding overview lesson covers the full mix.

Is the Samsara technical phone screen LeetCode?

Usually it isn't. The screen has run about an hour on a practical problem, often this one or another string-parsing task. A December 2025 candidate got a string-parsing question and advised being comfortable with regex. Prepare a few LeetCode mediums too, because some recent candidates got one.

Which language should I use?

Reports that mention it say the choice is yours. Python keeps string slicing and joins short, which helps when the clock is tight. Use whatever you can write and debug fastest under a timer.

How should I practice the converter?

Build it from a blank file in 30 minutes, one rule at a time, running the tests after each. Then do it again with the rules in a different order. Once that feels easy, add bold through a rule table and try the link scanner without regex.

Key Takeaways

  • ✓Markdown to HTML is the coding problem Samsara candidates name most, from 2019 through April 2026.
  • ✓Walk the lines once and track the run you are in. Blank lines and changes of kind close it.
  • ✓Keep inline rules in a table tried longest first, so a new rule from the interviewer is one line.
  • ✓Run your code after every rule. A 2025 senior candidate's only negative feedback was running it at the end.
Samsara interview guide

Know what Samsara asks before you walk in.

25 coding · 4 system design · 11 behavioral questions

Get Premium$49 a year · Instant access
Or start freeNo card.

Get their questions first.

The Samsara Online AssessmentHad your Samsara interview?How we research

InterviewLegend is independent and not affiliated with or endorsed by any company it covers.