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.

Google
Coding & Algorithms
Data Engineer
Google
November 29, 2026
Data Engineer
Technical Screen
Coding & Algorithms
Medium

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
State Machine
CSV Parsing
Escaping
Error Handling
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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 ...


Submit Your Answer
Markdown supported