CSV Parsing, Validation, And Joins
Asked of: Software Engineer
Last updated
What's being tested
These problems test CSV parsing, record validation, and join/aggregation algorithms over semi-structured text data. You must preserve input order where required, define duplicate-key and malformed-row behavior, and choose between straightforward scanning, sorting, or hash-based indexing. Strong solutions separate normalization, validation, and output formatting so edge cases are explicit and testable.
Patterns & templates
-
Use Python's
csv.readerorcsv.DictReader; handle quoted commas, escaped quotes, headers, blank lines, and malformed records deliberately. -
Normalize comparison fields with
strip(),casefold(), whitespace tokenization, and stop-word removal before forbidden-word or overlap checks. -
Build a hash index
key -> list[record]for joins; preserve every left row and emit all matching right rows, givingO(n + m + output)time. -
For sorted joins, sort both inputs by key and advance two pointers; complexity is
O(n log n + m log m)with lower auxiliary indexing overhead. -
Validate each row independently, collecting deterministic error codes; distinguish missing, empty, overlong, forbidden, and structurally malformed fields.
-
Aggregate changed files through
file -> ownersandowner -> changed filesmaps; deduplicate reviewers while retaining a specified stable ordering.
Common pitfalls
Pitfall: Treating CSV as
line.split(",")breaks quoted commas and embedded quotes; use a standards-aware parser.
Pitfall: Implementing a dictionary join as one-to-one silently drops duplicate matches; store lists and define the Cartesian expansion explicitly.
Pitfall: Calling
lower()without trimming, tokenizing, or removing ignored words produces inconsistent overlap and forbidden-word results.
Practice these
The practice cards below cover the canonical variants — solve all of them and time yourself.
Practice questions
- Validate CSV Company Records for Missing Fields, Length, Forbidden Words and OverlapStripe · Software Engineer · Technical Screen · medium
- Verify Business Records with Field and Name RulesStripe · Software Engineer · Technical Screen · medium
- Assign Reviewers from Changed FilesStripe · Software Engineer · Onsite · medium
- Implement a CSV dataset joinStripe · Software Engineer · Online Assessment · medium
Related concepts
- SQL/Python Data Manipulation And JoinsData Manipulation (SQL/Python)
- Parsing, Serialization, And DeserializationCoding & Algorithms
- Pandas Data ManipulationData Manipulation (SQL/Python)
- String Parsing, Tokenization, And ValidationCoding & Algorithms
- String Parsing, Palindromes, And NormalizationCoding & Algorithms
- String Processing, Parsing, And Output FormattingCoding & Algorithms