FastPrepSubdomain Visit Counts
Problems/Subdomain Visit Counts

Subdomain Visit Counts

Datadog logoDatadog● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The firsthand report supplies comma-delimited domain counts and code that adds each count to every dot suffix; its full nine-row input is retained. This exercise specifies sorted output, zero handling, valid input grammar, callable and bounds. The core task matches the report at about 95%.

Each row is a decimal visit count followed by a comma and a domain, such as 60,mail.yahoo.com. Add its count to that domain and to every suffix beginning after a dot. Thus the example contributes sixty visits to mail.yahoo.com, yahoo.com and com.

Combine contributions from all rows, including repeated domains. Return one string total,domain for every observed domain suffix, sorted lexicographically by the domain. Totals use ordinary decimal notation. Retain observed suffixes even when their total is zero. An empty input returns an empty array.

Domains are hierarchical string identifiers under the grammar below; do not use public-suffix rules or network lookups. A one-label domain contributes to itself.

Function

subdomainCounts(rows: String[]) → String[]

Examples

Example 1

rows = ["900,google.com","60,mail.yahoo.com","10,mobile.sports.yahoo.com","40,sports.yahoo.com","300,yahoo.com","10,stackoverflow.com","2,en.wikipedia.org","1,es.wikipedia.org","1,mobile.sports"]return = ["1320,com","2,en.wikipedia.org","1,es.wikipedia.org","900,google.com","60,mail.yahoo.com","1,mobile.sports","10,mobile.sports.yahoo.com","3,org","1,sports","50,sports.yahoo.com","10,stackoverflow.com","3,wikipedia.org","410,yahoo.com"]

The four inputs under yahoo.com contribute 60+10+40+300=410 there. The two under sports.yahoo.com contribute 10+40=50. The com total is 900+410+10=1320. The separate mobile.sports row also creates the one-label suffix sports.

Example 2

rows = ["5,a.b","7,b"]return = ["5,a.b","12,b"]

The first row contributes five to a.b and b. The second adds seven more to b, giving twelve. Sorting by domain puts a.b first.

Example 3

rows = []return = []

No suffix is observed, so the result is empty.

Constraints

  • 0 <= rows.length <= 100
  • Every row has between 3 and 71 characters and exactly the form count,domain, with no spaces.
  • A count is between 0 and 1000000000, written as 0 or without a leading zero.
  • A domain has between 1 and 5 dot-separated labels and at most 60 characters. Each label has 1 through 20 lowercase ASCII letters, digits or hyphens, and begins and ends with a letter or digit.
  • The sum of the domain lengths across all rows is at most 1000.

More Datadog problems

  • Query Log MatchPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Delete a Filesystem TreePHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Grouped-Query Attention Forward PassPHONE SCREEN · Seen Jun 2026
All Datadog interview questionsSee Datadog hiring insights
Saved
public String[] subdomainCounts(String[] rows) {
    // Write your code here.
}
Checking account…