Aggregate Visit Counts for Every Parent Domain in Access Logs

Last updated: November 29, 2026

Quick Overview

Given log lines like '9001 m.facebook.com' (a count followed by a domain), return the total visits for every domain and every parent domain, such as facebook.com and com, as strings in the same format.

Meta
Coding & Algorithms
Data Engineer
Meta
November 29, 2026
Data Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Given log lines like '9001 m.facebook.com' (a count followed by a domain), return the total visits for every domain and every parent domain, such as facebook.com and com, as strings in the same format.

Traffic analysis at Meta rolls hostnames up their domain hierarchy, and this warm-up checks basic parsing plus hash map aggregation. The interviewer expects clean splitting and a clear explanation of how each parent suffix is generated.

What the Interviewer Expects
  • Split each line into count and domain
  • Generate every suffix at dot boundaries
  • Aggregate counts in a hash map
  • Format output in the required count-space-domain form
  • State complexity in total characters
Key Topics to Cover
string parsing
hash map
aggregation
log processing
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 do this in SQL or Spark at warehouse scale?
  • How would you handle public suffixes like co.uk correctly?
  • How would you return the top k parent domains?
  • How would you treat malformed lines?
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
  • Each line has a positive integer, one space, and a domain of 1 to 3 or more labels separated by dots.
  • Count every domain and each suffix formed by dropping leading labels.
  • Output order does not ...
High-Level Design

For each line, split(' ', 1) into the count and the domain. Split the domain on . into labels. For k labels, the suffixes are '.'.join(labels[i:]) for i = 0..k-1. Add the count to each suffi...


Submit Your Answer
Markdown supported