Split Seller Inventory CSV Rows With Quoted Fields and Escaped Quotes
Last updated: November 29, 2026
Quick Overview
Sellers upload inventory feeds as CSV. Write a function that splits one line into fields, where a field may be wrapped in double quotes, may then contain commas, and represents a literal quote as two quotes (`""`).
Amazon
November 29, 20260
0
0 solved
Sellers upload inventory feeds as CSV. Write a function that splits one line into fields, where a field may be wrapped in double quotes, may then contain commas, and represents a literal quote as two quotes (`""`).
A screen question in the style of Amazon's seller and catalog ingestion teams, where malformed feeds are a daily reality and a naive `split(',')` corrupts titles like `"Mug, 12oz"`. The interviewer looks for a small state machine, clear rules for edge cases, and a strategy for reporting bad rows rather than crashing the whole feed.
What the Interviewer Expects
- Recognizes split(',') is wrong for quoted fields
- Implements an explicit in-quotes / out-of-quotes state machine
- Handles doubled quotes as a literal quote
- Preserves empty fields, including a trailing empty field
- Raises or reports on an unterminated quote
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
- How would you support fields that contain embedded newlines across physical lines?
- How would you process a 20 GB feed in a streaming way?
- How would you report which rows failed to the seller without dropping the whole upload?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
One logical line in, a list of strings out. Rules: a field starting with " is quoted until a closing quote; inside, "" is a literal quote and commas are data. Outside quotes, a comma ends the fiel...
High-Level Design
A two-state machine over characters: OUT and IN_QUOTES. In OUT, a quote at the start of a field switches to IN_QUOTES, a delimiter flushes the buffer, anything else appends. In IN_QUOTES, a ...