Implement SQL Table and DNA Ordering
MicrosoftSoftware Engineer · OnsiteLast updated
This question evaluates a candidate's skills in robust input parsing, in-memory data modeling, API design, and sequence reconstruction from linked fragments, covering string handling, edge-case handling for CSV, and graph-like ordering of sequence fragments.
Two independent coding exercises were asked. Solve both.
Problem A: CSV-backed in-memory table
Build a tiny in-memory relational table initialized from a CSV string.
Requirements:
- The first CSV row contains column names; subsequent rows contain values.
- Implement the CSV parser yourself. It must handle comma-separated fields, empty fields, quoted fields, commas inside quoted fields, escaped quotes represented as two consecutive double quotes, and newline characters inside quoted fields. Reject malformed CSV.
- Store the parsed data in memory.
- Expose a simple query API such as
select(projectedColumns, predicate), wherepredicateis a function evaluated on each row. Results should preserve input row order unless an explicit sort is added. - Discuss how you would extend the implementation with filtering operators, ordering, joins, or indexes.
Problem B: Order linked DNA sequence fragments
You are given fragments. In the base version, each fragment has start, end, and payload fields. The end of one fragment may equal the start of another fragment. All fragments form one valid chain with exactly one head and one tail.
Return the concatenation of the payloads in chain order.
Example:
[
{start: 'bbb', end: 'ccc', payload: '1'},
{start: 'aaa', end: 'bbb', payload: '2'},
{start: 'ccc', end: 'ddd', payload: '3'}
]
The correct chain is aaa -> bbb -> ccc -> ddd, so the payload order is 2, 1, 3, and the output is 213.
Follow-ups:
- Each fragment contains two endpoint labels and a payload, but it does not tell you which endpoint is the start and which is the end. Treat each fragment as an undirected edge and reconstruct any valid chain using all fragments.
- The input may contain multiple disconnected chains. Detect all chains or components and return the payload sequence for each one. Also explain how you would detect invalid inputs such as cycles, branches, or duplicate edges.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.