← Questions

Stepwise DNS resolver with aliasing

0
AnthropicCodingLast asked May 2026

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/ttl on every call and resolve_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_record calls, and are duplicates dropped?
  • What should add_record do on a name that is already an alias, and add_alias on 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.com match example.com itself, and does it match a.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 -> addresses and name -> 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 ts and 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

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