Split a CSV Export Line Respecting Quotes and Escaped Quotes
Last updated: November 29, 2026
Quick Overview
Write a parser that splits one line of a CSV export into fields, where fields may be wrapped in double quotes, quoted fields may contain commas, and a doubled quote inside a quoted field stands for a literal quote; report malformed lines.
0
0
0 solved
Write a parser that splits one line of a CSV export into fields, where fields may be wrapped in double quotes, quoted fields may contain commas, and a doubled quote inside a quoted field stands for a literal quote; report malformed lines.
Google Sheets and BigQuery imports both have to handle hand-edited CSV, so a Data Engineer screen often asks for a quote-aware splitter. The interviewer wants a clear state machine, correct escaped-quote handling, and an explicit stance on malformed input.
What the Interviewer Expects
- Explains why splitting on commas fails for quoted fields
- Uses an explicit in-quotes state and a field buffer
- Handles doubled quotes as escapes and empty fields at any position
- Detects unterminated quotes and stray quotes in unquoted fields
- Mentions how multi-line quoted fields change the design
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Quoted fields may contain newlines; how do you parse a whole file as a stream?
- Support a configurable delimiter and quote character, such as TSV exports.
- How would you parallelize parsing of a 50 GB CSV when record boundaries are ambiguous?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: one line, delimiter
,by default. - Quoted fields start with
"and end at the next"not followed by another";""inside means one literal quote. - Commas inside quotes are part of...
High-Level Design
A two-state machine is enough. Outside quotes, a delimiter ends the current field, a quote opens a quoted field (only allowed at the start of a field), and other characters go into the buffer. Inside ...