Problem · String
Normalize a DNS Domain Name
Learn this problemProblem statement
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) → StringExamples
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.