Code RoomStrip quoted comments
MediumPrep Room Coding #717

Strip quoted comments

CodingAlgorithms & data structuresEntry–Mid~13 min

Write the comment stripper for a dotfile format. In each line, a "#" begins a comment that runs to the end of the line — UNLESS the "#" sits inside a double-quoted region. Scanning left to right, each '"' toggles quoted mode (there are no escape characters, and a quote opened on a line may simply never close). After removing any comment, delete trailing spaces from what remains; keep leading whitespace untouched. Lines that end up empty disappear entirely. Return the surviving lines in their original order.

Implement
strip_inline_comments(lines: list[str]) → list[str]
Examples
in[["name=\"a # b\" # real comment","# full comment","port=80"]]out["name=\"a # b\"","port=80"]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 13 min
InputExpectedGot
[["name=\"a # b\" # real comment","# full comment","port=80"]]["name=\"a # b\"","port=80"]not run yetsample