FastPrepAggregate Access Counts for Domain Suffixes

Aggregate Access Counts for Domain Suffixes

Indeed logoIndeed● EasyFULLTIMEPHONE SCREEN
Learn

Problem statement

Each entry in records is count,domain, describing direct accesses to that full domain. For each observed domain suffix, return the sum of counts for full domains equal to that suffix or ending in . followed by it. A domain contributes to itself and every suffix formed by removing complete leftmost labels.

For this exercise, assume domains contain lowercase alphabetic labels separated by dots, with no empty label. Each record is valid and contains a nonnegative decimal count. Repeated records contribute separately.

For this exercise, assume the stated aggregation objective takes precedence over the source sample: its b.c.com and c.com totals should be 50 and 60, while com remains 960.

For this exercise, assume rows are [domain,total], ordered lexicographically by domain, with totals as decimal strings. Include observed suffixes with zero total; an empty input returns no rows.

Function

domainTotals(records: String[]) → String[][]

Examples

Example 1

records = ["900,google.com","20,a.b.c.com","30,b.c.com","10,c.com"]return = [["a.b.c.com","20"],["b.c.com","50"],["c.com","60"],["com","960"],["google.com","900"]]

Every count contributes to the full domain and each suffix. Thus b.c.com totals 50, c.com totals 60, and com totals 960; the source sample had inconsistent intermediate totals.

Example 2

records = ["5,mail.example.org","7,example.org"]return = [["example.org","12"],["mail.example.org","5"],["org","12"]]

example.org receives both direct visits and the five visits to mail.example.org.

Constraints

  • For this exercise, assume 0 <= records.length <= 10^4.
  • Each count is from 0 through 10^6.
  • Domain length is from 1 through 200; each lowercase label has length 1 through 20.
  • Total counts can exceed signed 32-bit range.

More Indeed problems

See Indeed hiring insights
public String[][] domainTotals(String[] records) {
    // Write your code here.
    return new String[0][0];
}
records["900,google.com","20,a.b.c.com","30,b.c.com","10,c.com"]
expected[["a.b.c.com", "20"], ["b.c.com", "50"], ["c.com", "60"], ["com", "960"], ["google.com", "900"]]
Checking account…