Stepwise DNS resolver with aliasing
I was asked this
No reports yet. Sign in to say where you were asked it.
A coding interview question asked in Anthropic's CodeSignal assessment, last asked May 2026. It tests networking, dns and design.
Build a simplified DNS resolver step by step against a fixed test harness: basic name lookup first, then alias layers on top. Later steps assume the earlier ones work.
-
Level 1:
add_record(name, ip),resolve(name): sorted addresses; names are case-insensitive and ignore a trailing dot. -
Level 2:
add_alias(alias, target); a name is either an alias or has addresses; cycles and chains over 16 hops resolve to[]. -
Level 3:
ts/ttlon every call andresolve_with_ttl(name, ts)returning(addresses, ttl_left). -
Level 4: wildcard names like
*.example.com; the closest enclosing wildcard answers, an exact name always wins.
class Resolver:
def add_record(self, name, ip, ts=0, ttl=None): ...
def add_alias(self, alias, target, ts=0, ttl=None): ...
def resolve(self, name, ts=0): ...
def resolve_with_ttl(self, name, ts=0): ...
Clarifying questions
- Can a name get several addresses through repeated
add_recordcalls, and are duplicates dropped? - What should
add_recorddo on a name that is already an alias, andadd_aliason a name that already has addresses: refuse, or replace? - Does an alias pointing at a missing name resolve to
[]? - Level 3: is the TTL left along an alias chain the smallest TTL of every hop? What does an entry with no TTL report?
- Level 4: does
*.example.commatchexample.comitself, and does it matcha.b.example.com?
What a strong answer covers
- One normalization function (lower-case, strip a trailing dot) applied on every write and read.
- Two maps,
name -> addressesandname -> target, with the rule that a name lives in only one. - Resolution as a loop that follows aliases with a hop counter and a seen set, returning
[]on a cycle or more than 16 hops. - TTL as an expiry per record, filtering expired entries at
tsand reporting the minimum time left along the chain. - Wildcards: for a name with no exact entry, try
*.plus each suffix from the closest outward, so the nearest enclosing wildcard wins. - Tests: case and trailing dot, a two-node cycle, exactly 16 and 17 hops, an expired hop in the middle of a chain, nested wildcards.
Follow-ups
- Cache the resolved chains and invalidate them when a record changes.
- Add negative caching for names that don't exist.
- Return addresses in round-robin order instead of sorted.
- How does a real recursive resolver differ from this one?
Where it's asked
- Anthropic · CodeSignal assessment · Last asked May 202690 min · Timed CodeSignal project in levels; the tests of one level must pass before the next one opens · No AI unless the instructions for the task allow it
What it tests
networking · dns · design
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. New accounts get 5 credits: each one unlocks a question for good.
What the labs asked this week
A weekly email of what OpenAI, Anthropic and the other top AI labs asked engineers, round by round.
Sign in to submit your code; every attempt is kept here.
