← Questions
Stepwise DNS resolver with aliasing
0
I was asked this
No reports yet. Sign in to say where you were asked it.
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): ...
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. Free with an account: one full answer per company.
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. Free with an account: one full answer per company.
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
