← Questions
Parse logs and count error codes
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Nuro's technical phone screen, last asked Feb 2026. It tests parsing, strings and hash maps.
Read the lines of a log, pull out the error code from each line that has one, and count how often each code appears. Real logs are messy: some lines have no code, and some are truncated or malformed. Skip what you can't parse, and count how many lines you skipped.
Interface
Unless you agree on a different interface with the interviewer, assume:
- Lines look like
<ISO timestamp> <LEVEL> <component> code=<CODE> <message>, whereLEVELisINFO,WARNorERRORandCODEisEfollowed by 3–5 digits. -
count_error_codes(lines: Iterable[str]) -> tuple[dict[str, int], int]returns counts of codes onERRORlines and the number of lines that were malformed.
Example
2026-03-01T10:00:00Z ERROR planner code=E1023 timeout waiting for map
2026-03-01T10:00:01Z INFO planner route ok
2026-03-01T10:00:02Z ERROR lidar code=E2001 dropped frames
2026-03-01T10:00:03Z ERROR planner code=E1023 timeout waiting for map
2026-03-01T10:00:04Z ERROR lidar code=
garbage line
count_error_codes(lines) -> ({"E1023": 2, "E2001": 1}, 2) # the empty code and the garbage line are malformed
Constraints
- Files can be gigabytes, so read line by line.
- Lines may contain non-UTF-8 bytes.
Clarifying questions
- What is the exact line format, and is it the same across components?
- Count codes only on
ERRORlines, or on any line? - What counts as malformed, and should malformed lines be returned or only counted?
- Do we need the top
kcodes, or all counts?
What a strong answer covers
- A precise regex (or split and validate) for the line format, anchored so a code inside a message isn't miscounted.
- Streaming the file with a
Counter, constant memory beyond the counts. - Robustness: decode with error handling, strip whitespace, skip and count malformed lines, never crash on one bad line.
- Sorting the output by count, then code, if a ranking is needed; the top
kwith a heap. - Tests for each malformed case and for the happy path.
Follow-ups
- Count codes per component and per hour.
- The logs are spread over 1,000 files on many machines. How do you count them all?
- Alert when a code's rate in the last five minutes is far above normal.
Where it's asked
- Nuro · Technical phone screen · Last asked Feb 2026
What it tests
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
