Normalize a DNS Domain Name
Reported by candidates from Anthropic's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks a first attempt on this Anthropic OA question, reported in July 2026, is appending a period without checking for one first. Then the second example returns "api.anthropic.com.." and you fail. The task is normalizeDnsName, the first step of a DNS resolver. Lowercase the whole string, make sure it ends with exactly one trailing dot. It's a string problem, and it's small. Small problems punish sloppiness, not weak algorithms. If your head goes blank on the edge cases mid-assessment, StealthCoder runs invisibly as a safety net and gives you the solution in real time.
The problem
Implement normalizeDnsName for the first step of a DNS resolver. DNS names are case-insensitive, so convert every letter to lowercase. By convention, a normalized DNS name ends with a trailing period (.). If the input does not already end with one, append it. Function normalizeDnsName(name: String) → String Examples Example 1 name = "Anthropic.COM" return = "anthropic.com." The name is lowercased and receives the conventional trailing period. Example 2 name = "api.Anthropic.com." return = "api.anthropic.com." The existing trailing period is preserved rather than duplicated.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is order and a guard. Lowercase the input, then check whether the last character is a period. If it isn't, append one. If it is, leave it alone. That's the whole algorithm, O(n) time for the lowercase pass. The common pitfall is the unconditional append, which breaks Example 2 by producing a double dot. The second pitfall is checking the original string's ending incorrectly, like indexing into an empty string and crashing. Think about what an empty input should return before you submit, since the spec doesn't say. Stick with the stated rules and don't invent extra validation like trimming whitespace or collapsing dots. Those aren't asked for. Use your language's built-in lowercase and a suffix check like endsWith. If the assessment surprises you with hidden cases and you freeze, StealthCoder is the hedge that stays invisible on screen share.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Normalize a DNS Domain Name cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Anthropic's OA.
Anthropic reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Normalize a DNS Domain Name FAQ
How hard is the Anthropic normalizeDnsName question really?+
Easy on algorithm, easy to botch on detail. There's no data structure or clever trick. You lowercase and conditionally append a period. Candidates lose points by skipping the check for an existing trailing dot, which the second example tests directly.
What's the trick to normalizeDnsName?+
Guard the append. Lowercase the string, then add a period only if it doesn't already end with one. An unconditional append turns "api.anthropic.com." into "api.anthropic.com.." and fails the preserved-period example.
What edge cases should I test before submitting?+
Test a name with no trailing period, one with a trailing period, and all-uppercase input. Also decide what an empty string does. The statement doesn't define it, so follow the rules literally and make sure your code doesn't crash on an empty index.
Is this kind of string normalization still asked in OAs?+
Yes, this one was reported for Anthropic in July 2026. Short spec-following problems show up as warm-ups or early parts of a multi-step question. A DNS resolver framing suggests later steps may build on this function, so keep it clean.
How do I prepare for this in 48 hours?+
Don't grind hard problems for this one. Practice reading a spec closely and walking each example by hand against your code. Write the function, then trace both examples line by line. Ten minutes of that beats an hour of unrelated problems.