Coding interviews
Reveal answer and reasoning
A chunked parser should retain its grammar state and any pending escape decision across chunks, while a decoder separately retains incomplete byte sequences. Report an error position in one chosen coordinate system and enforce total-record bounds across all chunks. Reinitializing limits for each chunk would allow an oversized record to bypass them.
Each input code unit is inspected a bounded number of times, giving O(n) time and O(n) output/buffer storage within the accepted input limit. The maxFields check bounds the number of fields. StringBuilder and final strings still allocate; this is not a zero-allocation parser. Splitting on commas first destroys the information needed to recognize quoted delimiters. Accepting arbitrary characters after a closing quote creates ambiguous recovery behavior.
Limits must apply before unbounded accumulation, and the parser should not return a partially accepted record after a grammar error.
The interview explanation should walk a quoted comma, a doubled quote, a trailing empty field and an invalid unfinished field. It should identify the three states and show why every code unit is processed only a bounded number of times. The real implementation intentionally solves a specified single-record grammar rather than claiming universal CSV compatibility. A senior extension separates decoding, chunk ownership, field grammar and resource bounds.
Correctness here comes from explicit transitions and complete failure behavior, not from recognizing a familiar file-format name and assuming Split will suffice.
What a strong answer covers
- A chunked parser should retain its grammar state and any pending escape decision across chunks, while a decoder separately retains incomplete byte sequences.
- Each input code unit is inspected a bounded number of times, giving O(n) time and O(n) output/buffer storage within the accepted input limit.
- Splitting on commas first destroys the information needed to recognize quoted delimiters.
Common pitfall
Splitting on commas first destroys the information needed to recognize quoted delimiters. Accepting arbitrary characters after a closing quote creates ambiguous recovery behavior. Limits must apply before unbounded accumulation, and the parser should not return a partially accepted record after a grammar error.
Follow-up questions
- Test an empty record, an empty quoted field, an embedded quote in an unquoted field and characters after a closing quote. Hint: specify the expected field count for an empty input before deciding whether it is an error.
- Which state must survive a chunk boundary immediately after the first quote of a doubled quote?
Self-review
Choose what to revisit. These marks are your own assessment and are separate from lesson completion.