Where it comes from
- Published by Palantir for all engineering rolesSource 1Writing Good CodePublisherPalantirSource typecompany hiring page More Palantir questions The Palantir interview guide
How to answer
Palantir’s company-wide guide to its coding interviews tells candidates to think about edge cases and the ways their code could break; it is not specific to the role. Source 1Writing Good CodePublisherPalantirSource typecompany hiring page This question makes that the whole task, so the list is what gets judged. A list is only useful if each line says what should happen.
- Pin the contract in one breath. What comes in, what comes out, and what failure looks like: an exception with a reason code, a
None, or a partial result. You cannot say an input breaks the parser until you know what correct means. - Walk a fixed set of categories out loud: empty, malformed, boundary, huge, unicode, and valid but surprising. A fixed order keeps you from stalling after the obvious three.
- Give a concrete input for each, with its expected result. Not “unicode” but
"1h"typed on a Japanese keyboard, and whether it is accepted. - Mark the product calls and ask. Whether a bare number means minutes is not yours to decide silently.
- Name the traps of your language. In Python,
\d,str.isdigit()andint()accept digits from other scripts, and$matches before a trailing newline. - Turn the list into a test table before the parser exists. It becomes the spec, and you run it at the end.
The trap is a list of category names with no inputs and no decisions. It sounds thorough and settles nothing.
Follow-ups
What the interviewer may ask next, once your first answer is on the table.
- Which of these would you reject, and which would you quietly fix? Who decides?
- The same field is filled in by users in Japan. What changes in your list?
- How would you find the inputs you did not think of?
- This parser runs on every request. Which of these inputs could hurt the service rather than the one caller?
Where answers go wrong
- Naming categories (“nulls, empty strings, big numbers”) with no concrete input and no expected result for each, so the list decides nothing.
- Writing the parser first and the list afterwards, so the list describes what the code happens to do rather than what it should do.
- Trusting
\dorstr.isdigit()to mean ASCII digits. In Python both accept digits from other scripts, such as Arabic-Indic١, andint()converts those;isdigit()also accepts superscripts like², whichint()rejects.
Answer this in two minutes
Write the answer you would say out loud. The clock starts with your first word.
Model answer
The interviewer’s parser: turn durations that people type into a scheduling field, such as 1h30m or 45m, into seconds. The scheduler refuses anything over 30d.