Parse Markdown Links Without Regex
SamsaraSoftware Engineer · Technical ScreenLast updated
This question evaluates proficiency in string parsing, tokenization, escape-sequence handling, and input validation required to convert simplified Markdown-style link syntax into HTML anchors without using regular expressions.
Implement a function that converts simplified link syntax text into an HTML anchor tag <a href="url">text</a> across an entire input string. Constraints: do not use regular expressions; rely only on basic string operations (e.g., indexOf, split, substring). Requirements:
- Support multiple links per line and across lines.
- Preserve all non-link text and punctuation.
- Leave malformed patterns (e.g., missing brackets or quotes) unchanged.
- If brackets appear inside the label, treat the innermost valid [ ... ] preceding a (" ... ") as the link label.
- Treat escaped brackets or quotes (preceded by a backslash ) as literals.
- Analyze the time and space complexity of your approach.
- Provide unit tests for typical, edge, and large inputs. Examples: Input: "Click Go to Link now." Output: "Click <a href="whateverlink.com">Go to Link</a> now." Input: "A and B" Output: "<a href="u1">A</a> and <a href="u2">B</a>" Input: "Broken label stays" Output: "Broken label stays"
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.