Problem · String

Normalize a DNS Domain Name

Learn this problem
EasyAnthropicINTERNOA

Problem 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) → 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.

More Anthropic problems

drafts saved locally
public String normalizeDnsName(String name) {
  // write your code here
}
name"Anthropic.COM"
expected"anthropic.com."
checking account