← Questions
Validate fixed-field records from a message file
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Stripe's technical phone screen, last asked Jan 2026. It tests parsing, validation and strings.
Validate the records in a message file. Each line starts with a datetime prefix, followed by the record's fields. Remove the prefix, then check that the rest is a well-formed record: exactly five fields, and none of them empty after trimming whitespace. The first field is the name. Return one result per line, in order.
Interface
Unless you agree on a different interface with the interviewer, assume:
-
validate(lines: list[str]) -> list[bool]— fields are separated by tab characters. The first field is the datetime prefix; it is dropped and not validated.
Example
"2026-01-17T10:00:00Z\talice\tmessage\tfile-1\tready\thello" -> True
"2026-01-17T10:01:00Z\t\tmessage\tfile-2\tready\thi" -> False # empty name
"2026-01-17T10:02:00Z\tbob\tmessage\tfile-3\tready" -> False # only four fields
"ignored\tann\ttype\tpath\t \tnote" -> False # a field of spaces is empty
Constraints
- Up to 10,000 lines, each at most 10,000 characters.
- Tabs are the only separators. Only the five record fields must be non-empty after trimming.
Clarifying questions
- Is the separator a tab, a comma or something else? Can it appear inside a field?
- Does a trailing tab (an empty sixth field) make the line invalid?
- Should the datetime prefix be validated too?
- Should the output say why a line is invalid?
- Is the file read all at once or streamed?
What a strong answer covers
- Split on the separator without dropping empty fields (
line.split("\t"), notsplit()), so a missing value is detected. - Exactly six parts: the prefix plus five fields. Trailing separators count as extra empty fields.
- Trimming each field before the empty check.
- Handling a line ending (
\r\n) without treating it as part of the last field. - O(total characters) time; streaming the file line by line.
- Tests: blank fields, extra and missing separators, whitespace-only fields, an empty line.
Follow-ups
- Return the reason for each invalid line.
- Validate the datetime prefix and the type of each field (for example, the third must be a file path).
- Fields can contain an escaped tab. How do you split now?
Where it's asked
- Stripe · Technical phone screen · Last asked Jan 202660 min · One realistic task in parts, in a project editor (CoderPad project mode or HackerRank Projects) with several files and tests
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
