Parsing interview problems

Parsing questions hand you text that a real system produced and ask you to turn it into structured data. Expect log lines with a fixed delimiter, CSV with quoted fields, key=value config files, HTTP-style headers or a tiny expression grammar. The interviewer is checking that you read the format spec carefully and pick the right tool. str.split(sep, maxsplit) and str.partition cover most delimited formats, csv.reader handles quoting so you don't have to, json.loads raises json.JSONDecodeError on bad input, and re.fullmatch is better than re.match when the whole line must conform.

The classic mistakes are splitting on whitespace when a field can contain spaces, forgetting maxsplit so a value containing the delimiter breaks the line, stripping too early or not at all, and wrapping the whole loop in one try so a single bad line kills the run. A strong answer validates each record on its own, skips or reports malformed input as the spec says, makes one pass without storing every line, and names the edge cases out loud before writing code. That covers empty input, a trailing newline, a field that is present but blank, and an integer that overflows the expected range.

2 open problems

  1. 01Inference Log Summaryeasy

    Parse pipe-delimited inference logs, skip malformed lines, and report request counts, successes and average latency per model.

  2. 36Delimited Stream Parsermedium

    Turn an iterator of arbitrary byte chunks into delimited messages, handling messages and multi-byte delimiters split across chunks.

5 locked

These open in order of demand. Open one and press I want this one to ask for it.

  1. 02Normalize Inference Requests Lockedeasy

    Parse raw JSON inference requests, validate required and optional fields, fill defaults and drop anything malformed.

  2. 03Parse an SSE Token Stream Lockedmedium

    Reassemble a streamed LLM response from Server-Sent Events chunks that can split anywhere, handling CRLF, junk payloads and [DONE].

  3. 38Stream Until Stop Sequence Lockedmedium

    Forward streamed LLM text until a stop sequence appears, holding back only a possible partial match even when it spans chunks.

  4. 39Streaming JSONL Parser Lockedmedium

    Parse JSON Lines from arbitrary byte chunks into records, handling split lines and UTF-8, with a strict mode and a skip-invalid mode.

  5. 40Length-Prefixed Message Parser Lockedmedium

    Decode a stream of 4-byte big-endian length-prefixed messages from arbitrary chunks, rejecting oversized and truncated frames.