Roll Up Visit Counts From Full Hostnames to Parent Domains

Last updated: November 29, 2026

Quick Overview

Given log entries like '9001 maps.google.com', where the number is a visit count, return the total visit count for every domain and parent domain (maps.google.com, google.com, com).

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Given log entries like '9001 maps.google.com', where the number is a visit count, return the total visit count for every domain and parent domain (maps.google.com, google.com, com).

A Google phone screen question about aggregating web traffic stats, close to how Search Console or analytics pipelines roll up hostnames. The interviewer looks for clean string parsing, a hash map accumulator, and awareness of suffix generation cost.

What the Interviewer Expects
  • Parses count and hostname correctly
  • Generates every parent suffix of the hostname
  • Accumulates counts in a dictionary
  • Returns output in the requested format
  • Discusses real-world issues like public suffixes (co.uk)
Key Topics to Cover
Hash Map
String Parsing
Aggregation
Suffixes
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you treat public suffixes like co.uk so that co.uk is not reported as a domain?
  • Return the top 10 parent domains by visits; what structure do you use?
  • How would you compute this over petabytes of logs?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: list of strings '<count> <hostname>', count is a non-negative integer, hostname has labels separated by dots.
  • Output: list of strings '<total> <domain>' for every domain level that appe...
High-Level Design

For each entry, split off the count, then split the hostname on dots into labels. A hostname with k labels has k suffix domains: the labels from index i to the end, for i in 0..k-1. Add the count to a...


Submit Your Answer
Markdown supported