Markdown to HTML Converter
- 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.
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 quoteblank or spaces stay close the p close the blockquotestarts with "> " open a blockquote close p, open quote add a lineanything else open a p add a line close quote, open pend of input done close the p close the blockquoteInline 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.
Markdown to HTML Converter
Problem
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.A single newline stays inside the paragraph as a line break. The blank line starts a second paragraph.
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.
Markdown to HTML Converter
Click "Run" to execute your code
<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.
Markdown to HTML With More Rules
Problem
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.
- MarkdownConverter()
- 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.
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.
Markdown to HTML With More Rules
Click "Run" to execute your code
**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.Markdown links without regex
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.
Markdown Links to Anchor Tags Without Regex
Problem
convert_links(text) that replaces every link written as [label]("url") with <a href="url">label</a>. Don't use regular expressions. Text outside links is copied as is.A link is
[, a label with no brackets in it, ], then (" immediately after, the URL, and "). If any piece is missing the input is malformed, and those characters stay exactly as typed.When brackets nest, the innermost pair is the link. In
[outer [inner]("u") only inner becomes a link, and the first [ stays plain.One well-formed link becomes an anchor. The text around it is copied as is.
Scan with an index. At each opening bracket, look ahead for the next bracket. If it is another opening bracket, this one is plain text. If it closes, check for the quoted URL right after it.
Markdown Links to Anchor Tags Without Regex
Click "Run" to execute your code
[ and move on, and the loop will reach the real link later. Interviewers who ask for tests want the malformed cases, so write those first.\[ is never an opener and \" doesn't end the URL. Skip escaped characters in every lookahead, then drop the backslashes from the label and URL. Turn a literal quote in the URL into " so the attribute stays valid. The solution works this through.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
HTML to Markdown for a Few Tags
Problem
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.
The line break becomes a newline, and the two paragraphs are separated by a blank line.
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.
HTML to Markdown for a Few Tags
Click "Run" to execute your code
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.
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 guideKnow what Samsara asks before you walk in.
25 coding · 4 system design · 11 behavioral questions
Get their questions first.
InterviewLegend is independent and not affiliated with or endorsed by any company it covers.